Bash convert epoch to date, showing wrong time
This particular timestamp is in milliseconds since the epoch, not the standard seconds since the epoch. Divide by 1000: $ date -d @1361234760.790 Mon Feb 18 17:46:00 MST 2013
This particular timestamp is in milliseconds since the epoch, not the standard seconds since the epoch. Divide by 1000: $ date -d @1361234760.790 Mon Feb 18 17:46:00 MST 2013
For 32-bit systems: fprintf(stdout, “%u\n”, (unsigned)time(NULL)); For 64-bit systems: fprintf(stdout, “%lu\n”, (unsigned long)time(NULL));
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.
The Unix Date command will display in epoch time the command is date +”%s” https://linux.die.net/man/1/date Edit: Some people have observed you asked for days, so it’s the result of that command divided by 86,400
You should be able to do this via the Instant class, which can represent a moment given the epoch time. If you have epoch seconds, you might create something via something like Instant i = Instant.ofEpochSecond(t); ZonedDateTime z = ZonedDateTime.ofInstant(i, zoneId);
Using SimpleDateFormat String string_date = “12-December-2012”; SimpleDateFormat f = new SimpleDateFormat(“dd-MMM-yyyy”); try { Date d = f.parse(string_date); long milliseconds = d.getTime(); } catch (ParseException e) { e.printStackTrace(); }
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
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
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
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