如何在 JAVA 中将纪元转换为 mySQL 时间戳 [英] How to convert epoch to mySQL timestamp in JAVA

查看:61
本文介绍了如何在 JAVA 中将纪元转换为 mySQL 时间戳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在mySQLtimestamp中获取mySQL时间戳格式?

How to get mySQL timestamp format in mySQLtimestamp?

long epochNow = System.currentTimeMillis()/1000;
long epochWeek = 604800;
long date7daysAgo = epochNo2013 w - epochWeek;
String mySQLtimestamp = /* 2013-09-23:50:00 */ 

推荐答案

为什么不一直使用普通的Date?

Why not use a normal Date all along?

Calendar cal = Calendar.getInstance();
cal.add(Calendar.DAY_OF_MONTH, -7);
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");  
String output = formatter.format(cal.getTime());

这篇关于如何在 JAVA 中将纪元转换为 mySQL 时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆