时间戳如何转换为日期格式?当初把日期格式转换为时间戳是为了更好的记录数据,现在如果想要看看当初时间戳被转换的时间,可以按照以下方法来实现,详情请阅读下文MySQL、C#、JS时间戳转换方法。
MySQL、C#、JS时间戳转换方法:
一、MySQL戳转换方法:
1、原理:
时间戳的原理是把时间格式转为十进制格式,这样就方便时间的计算,如:1377216000000 转化后是 2013年08月23日 。
2、步骤:
(1) 创建 DateUtilsl类。
(2) 输入代码:
- 01importjava.text.ParseException;
- 02importjava.text.SimpleDateFormat;
- 03importjava.util.Date;
- 04
- 07public class DateUtils {
- 08privateSimpleDateFormat sf = null;
- 09
- 10public static String getCurrentDate() {
- 11Date d = newDate();
- 12sf = newSimpleDateFormat("yyyy年MM月dd日");
- 13returnsf.format(d);
- 14}
- 15
- 16public static String getDateToString(long time) {
- 17Date d = newDate(time);
- 18sf = newSimpleDateFormat("yyyy年MM月dd日");
- 19returnsf.format(d);
- 20}
- 21
- 22public static long getStringToDate(String time) {
- 23sdf = newSimpleDateFormat("yyyy年MM月dd日");
- 24Date date = newDate();
- 25try{
- 26date = sdf.parse(time);
- 27} catch(ParseException e) {
- 28// TODO Auto-generated catch block
- 29e.printStackTrace();
- 30}
- 31returndate.getTime();
- 32}



