Home > Software engineering >  How to convert the date format "/Date(253402214400000 0000)/" into yyyyMMdd:hhmmss in Java
How to convert the date format "/Date(253402214400000 0000)/" into yyyyMMdd:hhmmss in Java

Time:01-27

Today we have the date/time in epoch format "/Date(16747622680000)/" which can be easy converted into yyyyMMdd:hhmmss when getting the digits as milliseconds from the String and pass it to an instance of java.util.Date today = new Date(16747622680000); and then use a java.text.SimpleDateFormat instance to get the expected result.

But what does the " 0000" in "/Date(253402214400000 0000)/" mean and how to convert that value?

CodePudding user response:

tl;dr

The 0000 means an offset from UTC of zero hours-minutes-seconds.

(Deleted last zero digit of example input, presumed typo)

Instant
.ofEpochMilli( 
    "/Date(1674762268000)/".replace( "/" , "" ).replace( "Date(" , "" ).replace( ")" , "" ).replace( "/" , "" )
)
.toString()

See this code run at IdeOne.com.

2023-01-26T19:44:28Z

  • Related