简体   繁体   English

如何从 C# 中的 DateTimeOffset 获取分钟?

[英]How to get minutes from DateTimeOffset in C#?

Someone gave me an example of this:有人给了我一个例子:

LA is behind 'UTC+0' by 8hrs, so is in timezone 'UTC+8' which is 480mins. LA 比 'UTC+0' 落后 8 小时,因此在时区 'UTC+8' 是 480 分钟。 The offset value should be the number of minutes to convert the UTCZ datetime back into the local time of the originating system, which in this cast is 480mins behind UTCZ… so the value in utcz_offset_mins should = -480.偏移值应该是将 UTCZ 日期时间转换回原始系统的本地时间的分钟数,在这个转换中是 UTCZ 后 480 分钟......所以 utcz_offset_mins 中的值应该 = -480。 (note the minus sign). (注意减号)。

Im tring with this:我正在考虑这个:

DateTimeOffset.UtcNow.UtcDateTime.Minute;

But it's not accurate, does someone know how to achieve it?但这不准确,有人知道如何实现吗?

If you are looking for your total offset from UTC in minutes, you need to use following:如果您要以分钟为单位查找与 UTC 的总偏移量,则需要使用以下命令:

DateTimeOffset.Now.Offset.TotalMinutes

The code you are trying does not access Offset but actually only access Minute part of UTC date time.您尝试的代码不会访问Offset ,但实际上只能访问 UTC 日期时间的Minute部分。

Your question is talking about time zones, but your example code is using the current time.您的问题是关于时区,但您的示例代码使用的是当前时间。 DateTimeOffset is an instance of time, similar to DateTime , but also incudes the UTC offset. DateTimeOffset是一个时间实例,类似于DateTime ,但也包含 UTC 偏移量。 The class you want to use is TimeZoneInfo .您要使用的 class 是TimeZoneInfo

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM