Solved

timezone headache - utc +10 as UTC

Posted on 2014-03-03
4
271 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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 Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Pass through dll 2 34
Response.Redirect Open new Form/tab/page? 5 19
Hidden Field Value 10 34
XML & .net 5 16
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

744 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now