Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. How did I not know this?

How did I not know this?

Scheduled Pinned Locked Moved The Lounge
csharpjavascriptcloudhelpwinforms
41 Posts 17 Posters 4 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Sander RosselS Sander Rossel

    So I'm working on an Azure app and one thing I do (and have done for 11 years now) is use DateTime.Now, which gives me the current system date and time. Never been an issue with WinForms apps or locally hosted apps. It's even never been an issue in web apps where I've used it for logging and the like. I've had to use specific time zones before, but always the user's client time zone. In this particular case, I need to save the system/company date and time and also report this back to the user. Azure uses UTC and I'm in The Netherlands though, so the time is always off by one or two hours (depending on summer or winter). The fix, apparently, is this:

    var timeZone = TimeZoneInfo.FindSystemTimeZoneById("W. Europe Standard Time");
    var now = TimeZoneInfo.ConvertTime(DateTime.UtcNow, timeZone);

    The "W. Europe Standard Time" is a bit of a magical string that will probably change in a few years when we're abolishing summer time (so make it a setting and don't hard code it!). You can get a list of these magical strings using tzutil /l (on Windows). I've always known DateTime.Now isn't really safe or anything, it's just never been an issue until now. DateTime.Today is specific and accurate enough for almost everything I do. And so I've learned how to get the date and time for a specific timezone after 11 years of programming :)

    Best, Sander Azure DevOps Succinctly (free eBook) Azure Serverless Succinctly (free eBook) Migrating Apps to the Cloud with Azure arrgh.js - Bringing LINQ to JavaScript

    E Offline
    E Offline
    englebart
    wrote on last edited by
    #41

    The same thing happens in Windows Explorer with DST. A file is changed at 10 AM standard time the Friday before DST changes. If you check the time stamp on Monday it will display an hour difference. File times are UTC-ish, it is the display time zone that changes. This was Win 7 behavior; I have not verified in Win 10.

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups