Last active
April 19, 2016 07:39
-
-
Save bestpika/7a00a6189d1d92963b35cfdc98ec4af0 to your computer and use it in GitHub Desktop.
功能筆記
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 清除空白、換行 | |
public static string clear(string text) | |
{ | |
var cls = new[] { "\r", "\n", " ", " " }; | |
foreach (var cl in cls) | |
{ | |
text = text.Replace(cl, string.Empty); | |
} | |
return text.Trim(); | |
} | |
// 民國轉西元 | |
public static DateTime gDate(string text) | |
{ | |
text = clear(text); | |
CultureInfo tw = new CultureInfo("zh-TW"); | |
tw.DateTimeFormat.Calendar = new TaiwanCalendar(); | |
return DateTime.ParseExact(text, "d", tw); | |
} | |
// 西元轉民國 | |
public static string twDate(string text, string format) | |
{ | |
text = clear(text); | |
CultureInfo tw = new CultureInfo("zh-TW"); | |
tw.DateTimeFormat.Calendar = new TaiwanCalendar(); | |
return DateTime.Parse(text).ToString(format, tw); | |
} | |
// 西元轉民國 | |
public static string twDate(DateTime date, string format) | |
{ | |
CultureInfo tw = new CultureInfo("zh-TW"); | |
tw.DateTimeFormat.Calendar = new TaiwanCalendar(); | |
return date.ToString(format, tw); | |
} | |
// DataTable to JSON String (JSON.Net) | |
public static string dt2JSONString(DataTable dt) | |
{ | |
return JsonConvert.SerializeObject(dt, Formatting.Indented); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment