Link to home
Start Free TrialLog in
Avatar of José Perez
José PerezFlag for Chile

asked on

Time Zone - Daylight saving Issue

I am programming an ASP.Net page with C#.
I have users from Australia (GMT +8) and Chile (GMT -3). Users uploads documento through this web the application.
It is very important that all documents have an exact (precise) creation date (YYY-MM-DD 00:00:00)
I need to display records in proper time whether it is for Chile users or Australian ones.
To stadarize, I am saving all times in GMT... Until here there is no issue... unless it is winter or summer...

In Chile they use "Daylight Saving" so if you are in Winter (July, August-September) you have GMT -3 and if you are in Summer (December, January-February) you have -4... and now raises the issue... how can I tell to my ASP.Net/C# application that if a record was saved in Summer the correct time is GMT-4 or if it was saved in Winter to use GMT -3?

I suspect that user machine can provide this information, but I don't know where.
Please I would really appreciate any help, comment or suggestion.
Many thanks.
Avatar of Karrtik Iyer
Karrtik Iyer
Flag of India image

Have you looked at the TimeZoneInfo class, it might do the work for you? You can save this information while saving the file and retrieve it while displaying the file again and convert the utc to local zone use this timezoneinfo class's  converttimefromutc function.
Avatar of Jacques Bourgeois (James Burger)
Jacques Bourgeois (James Burger)
Flag of Canada image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of José Perez


Yes, but that works ok for the present... now supposed you saved a document 3 years ago (in winter time GMT -4)  and you are now in summertime GMT -5. So you want to know the date and time it was saved. How will you tell your / C# app that you saved in GMT -4 or GMT -5?
There is a UTC component in the information that is saved with a file. The FileInfo class has a series of Utc methods on the dates.

I have never used them and do not have the time to test, but I would bet that they react as the OS does and that they take care of the situation at the location and time where the file was created.

Read the documentation carefully however. It looks like it uses the OS to do the job. It specifies that it's result is dependant upon the OS being kept properly configured and updated.
Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Frank Helk
The hint about UTC ("Universal Time Coordinated") is the important one.  UTC is the base of all local timestamps, and all local times are derived from it by applying offsets for location and DST.

UTC never has "steps" in it, besides the fact that every now and then a leap second is inserted or omitted to sync UTC with the unstabilities of earth's rotation. In that case the last minute of June 30 or Dec 31 has 61 or 59 seconds instead of the usual 60.

Most programming languages allow to derive UTC out of the DateTime objects (or from some system time value) by the runtime libs.

Besides of that, you should derive the timestamp on your server to prevent erronous (or possibly fraudulent) settings on your client's computers to interfere. If your server's clock is stable (see my article on NTP for a way to get reliable timekeeping), perfect timestamps should be achieved easy.
Resolved myself.