JojoMiss

疯魔jojo的后花园

导航

时间戳转换日期格式

1、时间戳 入参 String类型

import java.text.DateFormat;
import java.text.SimpleDateFormat;
// 毫秒时间戳转换日期格式:2023-04-21
def date = new Date(Long.parseLong("1712473439000"));// 需要转Long
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
def startDate = dateFormat.format(date);
logs.add('日志信息:'+startDate);

2、时间戳 入参 Int类型

import java.text.DateFormat;
import java.text.SimpleDateFormat;
// 毫秒时间戳转换日期格式:2023-04-21
def date = new Date(1712587518121);// 直接获取时间戳,无需转换类型
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
def formattedDate = dateFormat.format(date);
return formattedDate;

 

posted on 2024-04-08 22:47  幽忧一世  阅读(8)  评论(0编辑  收藏  举报

⭐️CSDN 我的文章列表⭐️
⭐WEIBO 微博首页⭐️
⭐园子 我的院子⭐️