Java时间和时间戳的相互转换
生活随笔
收集整理的這篇文章主要介紹了
Java时间和时间戳的相互转换
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
時間轉(zhuǎn)換為時間戳:
/* * 將時間轉(zhuǎn)換為時間戳*/ public static String dateToStamp(String s) throws ParseException{ String res; SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date date = simpleDateFormat.parse(s); long ts = date.getTime(); res = String.valueOf(ts); return res; }時間戳轉(zhuǎn)換為時間:
/* * 將時間戳轉(zhuǎn)換為時間*/public static String stampToDate(String s){ String res; SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); long lt = new Long(s); Date date = new Date(lt); res = simpleDateFormat.format(date); return res; }轉(zhuǎn)載于:https://www.cnblogs.com/runerering/p/5976486.html
總結(jié)
以上是生活随笔為你收集整理的Java时间和时间戳的相互转换的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 《C程序设计语言》- 字符输入和输出
- 下一篇: HTML 自学笔记(HTML框架+表单设