编程时间处理

golang

获取字符串时间

1
start_time :=time.Now().Format("2006-01-02 15:04:05")

时间差计算

1
2
3
start_time :=time.Now()
end_time :=time.Now()
d := end_time.Sub(start_time)

java

1
2
3
4
5
6
7
8
9
Calendar c = Calendar.getInstance();
c.setTime(new Date());
SimpleDateFormat hourPoint = new SimpleDateFormat("yyyy-MM-dd-HH");
SimpleDateFormat dayPoint = new SimpleDateFormat("yyyy-MM-dd");
String hourPointDate = hourPoint.format(c.getTime());
String dayPointDate = dayPoint.format(c.getTime());
long NowTime = c.getTimeInMillis();
c.add(Calendar.HOUR, -1);
long OneHourAgoTime = c.getTimeInMillis();