import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* @program: v1.0.0
* @description: 日期转换
* @author: lixy
* @create: 2023-02-09 11:05
**/
public class DateUtil {
/**
* @Description: 时间转换成时间戳,参数和返回值都是字符串
* @Param: s
* @return: res
* @Author: lixy
* @Date: 2023/2/9 11:07
*/
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;
}
/**
* @Description: 将时间戳转换为时间,参数和返回值都是字符串
* @Param: s
* @return: res
* @Author: lixy
* @Date: 2023/2/9 11:07
*/
public static String stampToDate(String s){
String res;
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
long lt = new Long(s);
Date date = new Date(lt);
res = simpleDateFormat.format(date);
return res;
}
}
日期和时间戳转换
于 2023-02-15 09:57:08 首次发布
博客围绕Java开发语言展开,但具体内容缺失。Java是重要的后端开发语言,应用广泛。
3142

被折叠的 条评论
为什么被折叠?



