1. 程式人生 > >使用java代碼將時間戳和時間互相轉換

使用java代碼將時間戳和時間互相轉換

時間戳 span null mss for class spa time() -m

時間戳轉時間:

SimpleDateFormat simpleDateFormat = null;

simpleDateFormat = new SimpleDateFormat("yyyyMMdd");
Date date = new Date(System.currentTimeMillis());
String day = simpleDateFormat.format(date);
simpleDateFormat = new SimpleDateFormat("HHmmss");  
String time
= simpleDateFormat1.format(date);

時間轉時間戳

SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = simpleDateFormat.parse(s);
long ts = date.getTime();

使用java代碼將時間戳和時間互相轉換