我以这种格式从javascript获取C#的日期:
"Tue Jan 15 00:00:00 UTC+0530 2008"
。
如何将其转换为"dd/MMM/yyyy"
格式?
答案 0 :(得分:1)
var jsdate = "Tue Jan 15 00:00:00 UTC+0530 2008";
var format = "ddd MMM d HH:mm:ss UTCzzzzz yyyy";
var date = DateTime.ParseExact(jsdate, format, CultureInfo.InvariantCulture);
Console.WriteLine(date.ToString("dd/MMM/yyyy"));
答案 1 :(得分:1)
试试这个:
var test = "Tue Jan 15 00:00:00 UTC+0530 2008";
const string format = "ddd MMM d HH:mm:ss zzz yyyy";
var var = DateTime.ParseExact(test.Replace("UTC", ""), format, CultureInfo.InvariantCulture);
Console.WriteLine(var);