How to get Date in java.util.Date instead of Unix Timestamp in bash script?
NickName:Netuddki Ask DateTime:2022-10-26T22:45:12

How to get Date in java.util.Date instead of Unix Timestamp in bash script?

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.

Copyright Notice:Content Author:「Netuddki」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/74209721/how-to-get-date-in-java-util-date-instead-of-unix-timestamp-in-bash-script

Answers
ikegami 2022-10-26T15:20:51

It's just unix epoch in milliseconds instead of seconds, so simply replace +%s with +%s%3N.\nepoch_milli=$( date -d 'today 00:00:00' +%s%3N )\n\n$ date +%s; date +%s%3N\n1666798614\n1666798614357\n\nConversion using your site",


More about “How to get Date in java.util.Date instead of Unix Timestamp in bash script?” related questions

How to get Date in java.util.Date instead of Unix Timestamp in bash script?

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&...

Show Detail

Java: Date from unix timestamp

I need to convert a unix timestamp to a date object. I tried this: java.util.Date time = new java.util.Date(timeStamp); Timestamp value is: 1280512800 The Date should be "2010/07/30 - 22:30:00" ...

Show Detail

Java: Date from unix timestamp

I need to convert a unix timestamp to a date object. I tried this: java.util.Date time = new java.util.Date(timeStamp); Timestamp value is: 1280512800 The Date should be "2010/07/30 - 22:30:00" ...

Show Detail

Java: Date from unix timestamp

I need to convert a unix timestamp to a date object. I tried this: java.util.Date time = new java.util.Date(timeStamp); Timestamp value is: 1280512800 The Date should be "2010/07/30 - 22:30:00" ...

Show Detail

Java: Date from unix timestamp

I need to convert a unix timestamp to a date object. I tried this: java.util.Date time = new java.util.Date(timeStamp); Timestamp value is: 1280512800 The Date should be "2010/07/30 - 22:30:00" ...

Show Detail

Bash script to convert a date and time column to unix timestamp in .csv

I am trying to create a script to convert two columns in a .csv file which are date and time into unix timestamps. So i need to get the date and time column from each row, convert it and insert it ...

Show Detail

How to convert DATE to UNIX TIMESTAMP in shell script on MacOS

On Linux you can convert a date like "2010-10-02" to a unix timestamp in shell script by date -d "2010-10-02" "+%s" Since Mac OS does not have the equivalent -d for date. How do you go about conv...

Show Detail

how to set string to timestamp in unix?

I have a String variable in unix script having data like '2017010110' (format is like -- %Y%m%d%H). Please note that its not System timestamp. Now I need to subtract -1 hour from 2017010110. Means...

Show Detail

How to force Hibernate to return dates as java.util.Date instead of Timestamp?

Situation: I have a persistable class with variable of java.util.Date type: import java.util.Date; @Entity @Table(name = "prd_period") @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)

Show Detail

Convert java.util.date default format to Timestamp in Java

The default format of java.util.date is something like this "Mon May 27 11:46:15 IST 2013". How can I convert this into timestamp and calculate in seconds the difference between the same and curren...

Show Detail