Convert Java Date to UTC String

tl;dr You asked: I was looking for a one-liner like: Ask and ye shall receive. Convert from terrible legacy class Date to its modern replacement, Instant. myJavaUtilDate.toInstant().toString() 2020-05-05T19:46:12.912Z java.time In Java 8 and later we have the new java.time package built in (Tutorial). Inspired by Joda-Time, defined by JSR 310, and extended by the ThreeTen-Extra … Read more

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

How to Convert UTC Date To Local time Zone in MySql Select Query

SELECT CONVERT_TZ() will work for that.but its not working for me. Why, what error do you get? SELECT CONVERT_TZ(displaytime,’GMT’,’MET’); should work if your column type is timestamp, or date http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_convert-tz Test how this works: SELECT CONVERT_TZ(a_ad_display.displaytime,’+00:00′,’+04:00′); Check your timezone-table SELECT * FROM mysql.time_zone; SELECT * FROM mysql.time_zone_name; http://dev.mysql.com/doc/refman/5.5/en/time-zone-support.html If those tables are empty, you have … Read more

Convert UTC into Local Time on Android

Here’s my attempt: String dateStr = “Jul 16, 2013 12:08:59 AM”; SimpleDateFormat df = new SimpleDateFormat(“MMM dd, yyyy HH:mm:ss a”, Locale.ENGLISH); df.setTimeZone(TimeZone.getTimeZone(“UTC”)); Date date = df.parse(dateStr); df.setTimeZone(TimeZone.getDefault()); String formattedDate = df.format(date); Also notice the “a” for the am/pm marker…

php convert datetime to UTC

Use strtotime to generate a timestamp from the given string (interpreted as local time) and use gmdate to get it as a formatted UTC date back. Example As requested, here’s a simple example: echo gmdate(‘d.m.Y H:i’, strtotime(‘2012-06-28 23:55’));

Is it always a good idea to store time in UTC or is this the case where storing in local time is better?

I think that in order to answer that question, we should think about the benefits of using UTC to store timestamps. I personally think that the main benefit to that is that the time is always (mostly) guaranteed to be consistent. In other words, whenever the timezone is changed, or DST applied, you don’t get … Read more