Convert a date format in epoch

This code shows how to use a java.text.SimpleDateFormat to parse a java.util.Date from a String: String str = “Jun 13 2003 23:11:52.454 UTC”; SimpleDateFormat df = new SimpleDateFormat(“MMM dd yyyy HH:mm:ss.SSS zzz”); Date date = df.parse(str); long epoch = date.getTime(); System.out.println(epoch); // 1055545912454 Date.getTime() returns the epoch time in milliseconds.

Converting epoch time with milliseconds to datetime

Use datetime.datetime.fromtimestamp: >>> import datetime >>> s = 1236472051807 / 1000.0 >>> datetime.datetime.fromtimestamp(s).strftime(‘%Y-%m-%d %H:%M:%S.%f’) ‘2009-03-08 09:27:31.807000’ %f directive is only supported by datetime.datetime.strftime, not by time.strftime. UPDATE Alternative using %, str.format: >>> import time >>> s, ms = divmod(1236472051807, 1000) # (1236472051, 807) >>> ‘%s.%03d’ % (time.strftime(‘%Y-%m-%d %H:%M:%S’, time.gmtime(s)), ms) ‘2009-03-08 00:27:31.807’ >>> ‘{}.{:03d}’.format(time.strftime(‘%Y-%m-%d %H:%M:%S’, … Read more

Convert Unix Epoch Time to Date in Google Sheets

The simplest way, not requiring any JS programming, would be through a formula, dividing by 86400 seconds per day and adding to January 1, 1970. For example the following gives 21 July 2017: =1500598288 / 86400 + DATE(1970, 1, 1) To convert a whole column of numbers, just use ARRAYFORMULA: =ARRAYFORMULA(A:A / 86400 + DATE(1970, … Read more

PostgreSQL: how to convert from Unix epoch to date?

You use to_timestamp function and then cast the timestamp to date select to_timestamp(epoch_column)::date; More details: /* Current time */ select now(); — returns timestamp /* Epoch from current time; Epoch is number of seconds since 1970-01-01 00:00:00+00 */ select extract(epoch from now()); /* Get back time from epoch */ — Option 1 – use to_timestamp … Read more

How to extract epoch from LocalDate and LocalDateTime?

The classes LocalDate and LocalDateTime do not contain information about the timezone or time offset, and seconds since epoch would be ambigious without this information. However, the objects have several methods to convert them into date/time objects with timezones by passing a ZoneId instance. LocalDate LocalDate date = …; ZoneId zoneId = ZoneId.systemDefault(); // or: … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)