Getting current date in milliseconds (UTC) (NO use of strings)
This is an old question but for the sake of the new visitors here is THE CORRECT ANSWER: Date.now(); It returns the number of milliseconds elapsed since 1 January 1970 00:00:00 UTC
This is an old question but for the sake of the new visitors here is THE CORRECT ANSWER: Date.now(); It returns the number of milliseconds elapsed since 1 January 1970 00:00:00 UTC
Both are fine. And neither is recommended except for a minority of purposes. What do you need milliseconds since the epoch for? In Java, we can have many different ways to get the current timestamp, For current timestamp just use Instant.now(). No need to convert to milliseconds. Many methods from the first years of Java, … Read more
Do you mean? long millis = System.currentTimeMillis() % 1000; BTW Windows doesn’t allow timetravel to 1969 C:\> date Enter the new date: (dd-mm-yy) 2/8/1969 The system cannot accept the date entered.
Surely you just need: double seconds = milliseconds / 1000.0; There’s no need to manually do the two parts separately – you just need floating point arithmetic, which the use of 1000.0 (as a double literal) forces. (I’m assuming your milliseconds value is an integer of some form.) Note that as usual with double, you … Read more
tl;dr LocalDateTime.parse( // With resolution of nanoseconds, represent the idea of a date and time somewhere, unspecified. Does *not* represent a moment, is *not* a point on the timeline. To determine an actual moment, place this date+time into context of a time zone (apply a `ZoneId` to get a `ZonedDateTime`). “2015-05-09 00:10:23.999750900” // A `String` … Read more
Use a Calendar to compute it : Calendar c = Calendar.getInstance(); c.add(Calendar.DAY_OF_MONTH, 1); c.set(Calendar.HOUR_OF_DAY, 0); c.set(Calendar.MINUTE, 0); c.set(Calendar.SECOND, 0); c.set(Calendar.MILLISECOND, 0); long howMany = (c.getTimeInMillis()-System.currentTimeMillis());
For an ever shorter conversion using java.util.concurrent.TimeUnit, equivalent to what Shawn wrote above, you can use: long durationInMs = TimeUnit.NANOSECONDS.toMillis(delayNS);
According to my test, with H2 version 1.3.170, the milliseconds are not actually zero, but 069: select * from test; ID DATE 1 2012-09-17 18:47:52.069 The same happens if you run: call parsedatetime(’17-09-2012 18:47:52.69′, ‘dd-MM-yyyy hh:mm:ss.SS’); If you add a zero then it works: call parsedatetime(’17-09-2012 18:47:52.690′, ‘dd-MM-yyyy hh:mm:ss.SS’); H2 internally uses java.text.SimpleDateFormat, so it … Read more
you can try: ffmpeg -i a.ogg -ss 00:01:02.500 -t 00:01:03.250 -c copy x2.ogg Timestamps need to be in HH:MM:SS.xxx format for advanced precision (where xxx are milliseconds). Let me know if it works.
You’re not using a number, you’re using a string that looks like a number. According to MDN, when you pass a string into Date, it expects a format recognized by the parse method (IETF-compliant RFC 2822 timestamps). An example of such a string is “December 17, 1995 03:24:00“, but you’re passing in a string that … Read more