I have an .sh script on my Linux server.
I need the date in milliseconds in Java, but everything I find on the net is giving me Unix Timestamp.
Like this: date=$(date -d 'today 00:00:00' " %s")
I need java milliseconds, like here: https://www.fileformat.info/tip/java/date2millis.htm.
How do I get that easily without writing a long java code? There has to be an easy solution.
CodePudding user response:
It's just unix epoch in milliseconds instead of seconds, so simply replace %s
with %s%3N
.
epoch_milli=$( date -d 'today 00:00:00' %s%3N )
$ date %s; date %s%3N
1666798614
1666798614357
CodePudding user response:
Assuming your date
supports this format
%N nanoseconds (000000000..999999999)
so you can do something like
date %s.%N
to get nanoseconds, then you can do the math if you want millies.