TimeUtils.java
962 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package com.cnlive.im.util;
import java.text.SimpleDateFormat;
/**
* Created by fan on 2016/6/23.
*/
public class TimeUtils {
//毫秒转秒
public static String long2String(long time){
//毫秒转秒
int sec = (int) time / 1000 ;
int min = sec / 60 ; //分钟
sec = sec % 60 ; //秒
if(min < 10){ //分钟补0
if(sec < 10){ //秒补0
return "0"+min+":0"+sec;
}else{
return "0"+min+":"+sec;
}
}else{
if(sec < 10){ //秒补0
return min+":0"+sec;
}else{
return min+":"+sec;
}
}
}
/**
* 返回当前时间的格式为 yyyy-MM-dd HH:mm:ss
* @return
*/
public static String getCurrentTime() {
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
return sdf.format(System.currentTimeMillis());
}
}