我有一个时间储存在普遍时间(UTC),价值2010-01 01:01:01。
我愿以这种格式以2010-01 04:01:01GMT-04:00表示,然而,时间区所用的K格式在《为确定时间区的工作》中并不奏效。
我有一个时间储存在普遍时间(UTC),价值2010-01 01:01:01。
我愿以这种格式以2010-01 04:01:01GMT-04:00表示,然而,时间区所用的K格式在《为确定时间区的工作》中并不奏效。
采用“zzz”格式的投机者获得“UTC”的抵消。 例如:
var dt = new DateTime(2010, 1, 1, 1, 1, 1, DateTimeKind.Utc);
string s = dt.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss "GMT"zzz");
Console.WriteLine(s);
Output: 2009-12-31 19:01:01 GMT-06:00
I m in the CDT timezone. 确保日期明确无误。 北方。
如同我一样,你需要一种格式,如<条码>2018-03-31T01:23:45.678-0300<>>。 (时区没有殖民地),你可以这样做:
datetime.ToString("yyyy-MM-ddTHH:mm:ss.fffzzz").Remove(26,1)
这种方法将回到东部标准时间的指定时间(如问题要求), 甚至如果无害环境技术不是当地时间区<>:
public string GetTimeInEasternStandardTime(DateTime time)
{
TimeZoneInfo easternStandardTime = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time");
DateTimeOffset timeInEST = TimeZoneInfo.ConvertTime(time, easternStandardTime);
return timeInEST.ToString("yyyy-MM-dd hh:mm:ss tt" GMT"zzz");
}
注:我没有在非英语的非洲顾问处测试。 见。 TimeZoneInfo.FindSystemtimeZoneById。
与这项工作类似。 也许可以把它清理起来更远:
string newDate = string.Format("{0:yyyy-MM-dd HH:mm:ss} GMT {1}", dt.ToLocalTime(), dt.ToLocalTime().ToString("%K"));
I think you are looking for the TimeZoneInfo
class (see http://msdn.microsoft.com/en-us/library/system.timezoneinfo_members.aspx). It has many static methods to convert dates between time zones.
What is the use of default keyword in C#? Is it introduced in C# 3.0 ?
I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...
I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...
I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...
I have two EF entities. One has a property called HouseNumber. The other has two properties, one called StartHouseNumber and one called EndHouseNumber. I want to create a many to many association ...
How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...
Since I cannot order my dictionary, what is the best way of going about taking key value pairs and also maintaing an index?
Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...