static void Main(string[] args) { NepDate daate = new NepDate(); daate.setNepDate(2075, 05, 25); NepDateConverter conv = new NepDateConverter(); DateTime a = NepDateConverter.NepToEng(2076, 5, 30); Console.WriteLine("DateConversion:::::"); Console.WriteLine(a); var b = NepDateConverter.EngToNep(2019, 7, 16); b.ToLongDateString(); Console.WriteLine("DateConversion:::::"); Console.WriteLine(b.ToLongsDateString()); Console.WriteLine(b.Year); Console.WriteLine(b.Month); Console.WriteLine(b.Day); //if (b.Month < 4) //{ // Console.WriteLine("FisalYear :"+(b.Year - 1)+"/"+ b.Year); //} //else //{ // Console.WriteLine("FisalYear :" + (b.Year) + "/" + (b.Year+1)); //} }
public static DateTime NepToEng(NepDate dateTime) { return(NepToEng(dateTime.Year, dateTime.Month, dateTime.Day)); }
public static NepDate EngToNep(int yy, int mm, int dd) { if (bs == null) { InitializeData(); } if (IsRangeEng(yy, mm, dd) == false) { return(null); } else { // english month data. int[] month = new int[] { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; int[] lmonth = new int[] { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; int def_eyy = 1944; //spear head english date... int def_nyy = 2000; int def_nmm = 9; int def_ndd = 17 - 1; //spear head nepali date... int total_eDays = 0; int total_nDays = 0; int a = 0; int day = 7 - 1; //all the initializations... int m = 0; int y = 0; int i = 0; int j = 0; int numDay = 0; // count total no. of days in-terms of year for (i = 0; i < (yy - def_eyy); i++) { //total days for month calculation...(english) if (IsLeapYear(def_eyy + i)) { for (j = 0; j < 12; j++) { total_eDays += lmonth[j]; } } else { for (j = 0; j < 12; j++) { total_eDays += month[j]; } } } // count total no. of days in-terms of month for (i = 0; i < (mm - 1); i++) { if (IsLeapYear(yy)) { total_eDays += lmonth[i]; } else { total_eDays += month[i]; } } // count total no. of days in-terms of date total_eDays += dd; i = 0; j = def_nmm; total_nDays = def_ndd; m = def_nmm; y = def_nyy; // count nepali date from array while (total_eDays != 0) { a = bs[i][j]; total_nDays++; //count the days day++; //count the days interms of 7 days if (total_nDays > a) { m++; total_nDays = 1; j++; } if (day > 7) { day = 1; } if (m > 12) { y++; m = 1; } if (j > 12) { j = 1; i++; } total_eDays--; } numDay = day; var nepDate = new NepDate(); nepDate.Year = y; nepDate.Month = m; nepDate.Day = total_nDays; nepDate.WeekDayName = GetDayOfWeek(day); nepDate.MonthName = GetNepaliMonth(m); nepDate.WeekDay = numDay; return(nepDate); } }