Solved

timezone headache - utc +10 as UTC

Posted on 2014-03-03
4
288 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 53

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 36

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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

752 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