开发者

How to change string to date in Java

开发者 https://www.devze.com 2023-01-11 04:03 出处:网络
i need to to conver开发者_开发百科t an string to date format in java i have an string that i get from torrent file

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消