How to change string to date in Java
i need to to conver开发者_开发百科t an string to date format in java i have an string that i get from torrent file
the string is like 1278622088
That's a timestamp in seconds. You can use the constructor of java.util.Date
taking a timestamp in milliseconds. You first need to convert the String
to Long
using Long#valueOf()
and then multiply with 1000
.
String timestamp = "1278622088";
Date date = new Date(Long.valueOf(timestamp) * 1000);
you can pass a Long
value to new Date()
So as long as you can parse your String
to a Long
value, you're ok.
精彩评论