C# 西元轉民國
System.Globalization.TaiwanCalendar twC = new System.Globalization.TaiwanCalendar();
DateTime dtime;
dtime = (DateTime)dr[i]; //dr抓出來的西元日期
// twC.GetYear 取得民國年,再補0到3位,例如033
// twC.GetMonth 取得月份
// twC.GetDayOfMonth(dtime) 取得日期
row[i] = twC.GetYear(dtime).ToString().PadLeft(3, '0') + twC.GetMonth(dtime).ToString().PadLeft(2, '0') + twC.GetDayOfMonth(dtime).ToString().PadLeft(2, '0');
下面這樣也ok,會得到民國時間
CultureInfo cui = new CultureInfo("zh-TW", true);
cui.DateTimeFormat.Calendar = new TaiwanCalendar();
DateTime.Now.ToString("yyMMdd", cui);
分別為星期一到星期日的日期
DateTime.Now.AddDays(Convert.ToDouble((1 - Convert.ToInt16(DateTime.Now.DayOfWeek)))).ToString("yyMMdd", cui);
DateTime.Now.AddDays(Convert.ToDouble((2 - Convert.ToInt16(DateTime.Now.DayOfWeek)))).ToString("yyMMdd", cui);
DateTime.Now.AddDays(Convert.ToDouble((3 - Convert.ToInt16(DateTime.Now.DayOfWeek)))).ToString("yyMMdd", cui);
DateTime.Now.AddDays(Convert.ToDouble((4 - Convert.ToInt16(DateTime.Now.DayOfWeek)))).ToString("yyMMdd", cui);
DateTime.Now.AddDays(Convert.ToDouble((5 - Convert.ToInt16(DateTime.Now.DayOfWeek)))).ToString("yyMMdd", cui);
DateTime.Now.AddDays(Convert.ToDouble((6 - Convert.ToInt16(DateTime.Now.DayOfWeek)))).ToString("yyMMdd", cui);
DateTime.Now.AddDays(Convert.ToDouble((7 - Convert.ToInt16(DateTime.Now.DayOfWeek)))).ToString("yyMMdd", cui);
沒有留言:
張貼留言