Solved

timezone headache - utc +10 as UTC

Posted on 2014-03-03
4
282 Views
Last Modified: 2014-03-04
I have all my data stored in utc format
some users have their user account set to different time zones for example UTC + 10, so they need to filter data within their time zone days

for example, i want to filter a days data ( the 28th Feb)
according to the attached, if i want to select the days data for brisbane, its UTC time is 14:00 to 13:59 the next day

however, this code is always selecting 10:00am UTC
 public static String GetUsersLocalDateTime(DateTime utcTime, string timeZone)
        {
//            DateTime userTimeZoneDateTime = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(Convert.ToDateTime(utcTime.ToString("yyyy-MM-dd HH:mm:ss")), timeZone);
         

Open in new window


of course this is just doing a UTC +10 conversion on time

but really the UTC time for midnight in brisbane is 14:00 gmt/utc

what code do i need to get the 24 hour period for brisbane
Book1.xlsx
0
Comment
Question by:websss
4 Comments
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 39902681
I don't develop in c# and only answering because of the neglected alert.

In vbs I use dateadd for this and it looks like in c# there is the same http://msdn.microsoft.com/en-us/library/b1zcctd2(v=vs.110).aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-1

public static DateTime DateAdd(
      string Interval,
      double Number,
      Object DateValue
)

You just need to add or subtract the hours from UTC
0
 
LVL 18

Assisted Solution

by:Dennis Aries
Dennis Aries earned 250 total points
ID: 39902749
You can easily convert from UTC to another timezone:

// Note: userTimeZone is the string format of the timezone requested

TimeZoneInfo userZone = TimeZoneInfo.FindSystemTimeZoneById(userTimeZone);
DateTime userTime = TimeZoneInfo.ConvertTimeFromUtc(timeUtc, userZone);

Open in new window


You can use
TimeZone.CurrentTimeZone

Open in new window

to retrieve the currently used timezone, but if you run the code on the server, then it will always return the server timezone (presumably UTC). For websites, it is common practise to have the user select a timezone in his/her profile and do the conversions according to that setting., in which case the first snippet will suffice.
0
 
LVL 35

Accepted Solution

by:
Miguel Oz earned 250 total points
ID: 39902824
There are two approches for this issue:
1) Keep all times server based time: In other words any UTC time will be converted to local server time before being rendered to the client browser.
Adv: Easy to implement.
Disadv: It does not take in account the client browser timezone.
This is the approach you are doing right now if you are coding in the server.

2) Transmit the time as UTC and let the browser display it as local time based on the client timezone machine in javascript:
var date = new Date('2012-11-29 17:00:34 UTC');
var timeAsString  = date.toString();

Open in new window

Adv:  It takes in account the client browser timezone.  
Disadv: More difficult to implement because it need to use Javascript to convert the times in the client browser. Keep in mind that it may be confusing for your support people if they work in different time zones, for example supprot team is in Sydney, UK and India, all of them will look at different reported time unless there are process in place to remind them that a time conversion is required.
0
 

Author Comment

by:websss
ID: 39902863
Actually this was the solution
public static String ConvertUtcDateTimeToLocalDateTime(DateTime utcTime, string localTimeZone)
        {
            //Pass in a UTC time and it will return the users Timezone date time
            DateTime localTime = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(utcTime, localTimeZone, "UTC");
            return localTime.ToString("yyyy-MM-dd HH:mm:ss");
        }

Open in new window


will give points for effort
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

822 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question