Android get Current UTC time [duplicate]

System.currentTimeMillis() does give you the number of milliseconds since January 1, 1970 00:00:00 UTC. The reason you see local times might be because you convert a Date instance to a string before using it. You can use DateFormats to convert Dates to Strings in any timezone: DateFormat df = DateFormat.getTimeInstance(); df.setTimeZone(TimeZone.getTimeZone(“gmt”)); String gmtTime = df.format(new … Read more

Python: Figure out local timezone

In Python 3.x, local timezone can be figured out like this: >>> import datetime >>> print(datetime.datetime.now(datetime.timezone.utc).astimezone().tzinfo) AEST It’s a tricky use of datetime‘s code . For python < 3.6, you’ll need >>> import datetime >>> print(datetime.datetime.now(datetime.timezone(datetime.timedelta(0))).astimezone().tzinfo) AEST

How to convert DateTime in Specific timezone?

The .NET framework already has classes and methods available to convert DateTimes between different time zones. Have a look at the ConvertTime methods of the TimeZoneInfo class. Edit: When you get the time to put into the database, assuming it was created with correct time zone information you can easily convert to UTC: DateTime utcTime … Read more

Convert UTC to current locale time

It has a set timezone method: SimpleDateFormat simpleDateFormat = new SimpleDateFormat(“yyyy-MM-dd HH:mm:ss”); simpleDateFormat.setTimeZone(TimeZone.getTimeZone(“UTC”)); Date myDate = simpleDateFormat.parse(rawQuestion.getString(“AskDateTime”)); all done!

Difference between UTC and GMT Standard Time in .NET

GMT does not adjust for Daylight saving time (DST). You can hear it from the horse’s mouth on this web site. Add this line of code to see the source of the problem: Console.WriteLine(TimeZoneInfo.FindSystemTimeZoneById(“GMT Standard Time”).SupportsDaylightSavingTime); Output: True. This is not a .NET problem, it is Windows messing up. The registry key that TimeZoneInfo uses … Read more

Objective-C setting NSDate to current UTC

[NSDate date]; You may want to create a category that does something like this: -(NSString *)getUTCFormateDate:(NSDate *)localDate { NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; NSTimeZone *timeZone = [NSTimeZone timeZoneWithName:@”UTC”]; [dateFormatter setTimeZone:timeZone]; [dateFormatter setDateFormat:@”yyyy-MM-dd HH:mm:ss”]; NSString *dateString = [dateFormatter stringFromDate:localDate]; [dateFormatter release]; return dateString; }

Best practices with saving datetime & timezone info in database when data is dependant on datetime

Hugo’s answer is mostly correct, but I’ll add a few key points: When you’re storing the customer’s time zone, do NOT store a numerical offset. As others have pointed out, the offset from UTC is only for a single point in time, and can easily change for DST and for other reasons. Instead, you should … Read more