获取系统时间戳
public String getTime(){
long time=System.currentTimeMillis()/1000;//获取系统时间的10位的时间戳
String str=String.valueOf(time);
return str;
}
、获取系统时间
long currentTime = System.currentTimeMillis();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy年-MM月dd日-HH时mm分ss秒");
Date date = new Date(currentTime);
System.out.println(formatter.format(date));
结果如下
2017年-05月26日-14时49分29秒
时间戳转换日期
public static String timetodate(String time) {
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(Long.valueOf(time));
SimpleDateFormat sf = new SimpleDateFormat("MM-dd ");//这里的格式可换"yyyy年-MM月dd日-HH时mm分ss秒"等等格式
String date = sf.format(calendar.getTime());
return date;
}
时间日期转换成时间戳
/*
* 将时间转换为时间戳
*/
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;
}
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有