/Date(1635476150707)/ 转化成时间
所谓时间戳,是指自格林威治时间1970年01月01日00时00分00秒(北京时间1970年01月01日08时00分00秒)起至现在的总秒数。
有些情况下,后台可能会将所有的时间都转换成时间戳返回给我们前端,这是我们就需要将时间戳转换成时间,并将时间进行格式化。
static String DateTimeFromInt(String? date) {
try {
if(date is String){
String dateint = date.substring(6, 19);
DateTime dt = DateTime.fromMicrosecondsSinceEpoch(
(int.parse(dateint) + 8 * 60 * 60) * 1000); //加上8 时区
return formatDate(dt, [yyyy, '-', mm, '-', dd , ' ' ,HH,':',n]);
}else
{
return "";
}
} catch (e) {
return "";
}
}
DateTimeFromInt(“/Date(1635476150707)/ ”)
结果
2021-10-29 10:56