08:15:16 April 1, 2010 PDT
我需要将其保存到MSSQL数据库中的DateTime,但我无法在C#中转换。有人能帮我铸造吗?"PDT
"到底是什么?
这篇文章与分析日期时间有关,时区格式为PST/CEST/UTC/etc
我不知道如何从字母时区转换为数字时区,但在你这样做之后,你可以
DateTime myDate = Convert.ToDateTime("Thu, 18 Mar 2004 14:52:56-07:00");
更新:此链接显然包含将"PDT"转换为GMT偏移量的代码。http://bytes.com/topic/c-sharp/answers/214648-how-do-i-parse-date-w-time-zone还可以查看TimeZoneInfo类http://msdn.microsoft.com/en-us/library/system.timezoneinfo.aspx
这篇文章中的代码似乎运行良好:http://www.codeillustrator.com/2010/03/converting-paypal-paymentdate-to-net.html
using System;
using System.Globalization;
public static class PayPalTransaction
{
public static DateTime ConvertPayPalDateTime(string payPalDateTime)
{
// accept a few different date formats because of PST/PDT timezone and slight month difference in sandbox vs. prod.
string[] dateFormats = { "HH:mm:ss MMM dd, yyyy PST", "HH:mm:ss MMM. dd, yyyy PST", "HH:mm:ss MMM dd, yyyy PDT", "HH:mm:ss MMM. dd, yyyy PDT" };
DateTime outputDateTime;
DateTime.TryParseExact(payPalDateTime, dateFormats, new CultureInfo("en-US"), DateTimeStyles.None, out outputDateTime);
// convert to local timezone
outputDateTime = outputDateTime.AddHours(3);
return outputDateTime;
}
}
(回答交叉发布的类似问题:如何将Paypal';s HH:MM:SS DD Mmm(.)YYYY PST/PDT转换为C#UTC DateTime?)