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

JavaScriptSerializer UTC DateTime issues

JavaScriptSerializer, and DataContractJsonSerializer are riddled with bugs. Use json.net instead. Even Microsoft has made this switch in ASP.Net MVC4 and other recent projects. The /Date(286769410010)/ format is proprietary and made up by Microsoft. It has problems, and is not widely supported. You should use the 1979-02-02T02:10:10Z format everywhere. This is defined in ISO8601 and RF3339. … 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

Why does Java’s java.time.format.DateTimeFormatter#format(LocalDateTime) add a year?

From Wikipedia: [YYYY] indicates the ISO week-numbering year which is slightly different from the traditional Gregorian calendar year (see below). YYYY is an ISO-8601 style representation of the year. yyyy is the Gregorian year-of-era representation. Since the the calculation of the two can be different by +1 or -1, hence the formatting. More useful info … 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’));