如何判断是英国夏令时 [英] How to tell if it's British Summer Time

查看:131
本文介绍了如何判断是英国夏令时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码,应该返回60的偏移量(以表明目前在英国,我们处于英国夏令时-即格林尼治标准时间之前60分钟):

I have the following code, which should return an offset of 60 (to show that in the UK at present, we are in British Summer Time - ie. 60 minutes ahead of GMT):

var info = TimeZoneInfo.FindSystemTimeZoneById("Greenwich Standard Time");
DateTimeOffset localServerTime = DateTimeOffset.Now;
double off = localServerTime.Offset.TotalMinutes;
return off;

但是,它返回0。

有人可以帮我解决这个问题吗?

Could anyone please help fix this for me?

推荐答案

使用 TimeZoneInfo.IsDaylightSavingTime方法(DateTimeOffset)来查找您的时区当前是否为夏时制。

Use TimeZoneInfo.IsDaylightSavingTime Method (DateTimeOffset) to find if it is currently Daylight saving for your Timezone.

var info = TimeZoneInfo.FindSystemTimeZoneById("Greenwich Standard Time");
DateTimeOffset localServerTime = DateTimeOffset.Now;
bool isDaylightSaving = info.IsDaylightSavingTime(localServerTime);

还有其他示例此处

这篇关于如何判断是英国夏令时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆