package com.jia.dimensions_of_electricity.util;
import java.text.SimpleDateFormat;
import java.util.Date;
public class TimeUtils {
private static SimpleDateFormat sf = null;
/**
* (int)时间戳转Date
*
* @param timestamp
* @return
*/
public static Date stampForDate(Integer timestamp) {
return new Date((long) timestamp * 1000);
}
/**
* (long)时间戳转Date
*
* @param timestamp
* @return
*/
public static Date longStampForDate(long timestamp) {
return new Date(timestamp);
}
/**
* (long)时间戳转string
*
* @param time
* @return
*/
public static String getDateToString(long time) {
Date d = new Date(time);
sf = new SimpleDateFormat(\"yyyy-MM-dd HH:mm:ss\");
return sf.format(d);
}
/**
* string转(long)时间戳
* @param time
* @return
*/
public static long getStringToDate(String time) {
sf = new SimpleDateFormat(\"yyyy-MM-dd HH:mm:ss\");
Date date = new Date();
try {
date = sf.parse(time);
} catch (Exception e) {
e.printStackTrace();
}
return date.getTime();
}
/**
* date转String
*
* @param date
* @return
*/
public static String dateForString(Date date) {
SimpleDateFormat sdf = new SimpleDateFormat(\"yyyy-MM-dd HH:mm:ss\");//时间的格式
return sdf.format(date);
}
/**
* String转Date
*
* @param time
* @return
*/
public static Date stringForDate(String time) {
SimpleDateFormat sdf = new SimpleDateFormat(\"yyyy-MM-dd HH:mm:ss\");//时间的格式
Date date = null;
try {
date = sdf.parse(time);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return date;
}
/**
* Date转时间戳
*
* @param data
* @return
*/
public static Integer dateForStamp(Date data) {
return (int) (data.getTime() / 1000);
}
}
继续阅读与本文标签相同的文章
下一篇 :
如何用神经网络“寻找威利”
-
CAD如何批量导出PDF文件?别说PDF了!GIF我都能给你导出来
2026-05-19栏目: 教程
-
活动回顾丨阿里云业务中台最佳实践沙龙圆满落幕
2026-05-19栏目: 教程
-
在CentOS里查看ssh的登录记录
2026-05-19栏目: 教程
-
好程序员web前端学习路线分享纯css绘制各种图形
2026-05-19栏目: 教程
-
菜鸟裹裹快递员收入有多高?小哥晒出月流水,程序员表示羡慕了
2026-05-19栏目: 教程
