How to tell if it's British Summer Time

前端 未结 4 524
猫巷女王i
猫巷女王i 2021-01-19 02:21

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):

4条回答
  •  深忆病人
    2021-01-19 02:51

    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);
    

    There are further examples here

提交回复
热议问题