记录长度:先记录,后整理
当前日期: 2021-10-12
时间戳长度: 10位(秒)1634017713,13位(毫秒)1634017713684
下面程序生成的时间/时间戳,是当前时区还是 UTC默认的时区的时间。要具体看服务器的配置。
Javascript:new Date(<时间戳(毫秒长度)>); new Date(<字符串: 格式=yyyy[-MM-dd [hh:]mm:ss]>); /// 获取时间戳 new Date().getTime();
Java:
import java.time.Instant; import java.time.LocalDateTime; import java.time.LocalDate; /// ... LocalDateTime localDateTime = Instant /// 解析时间戳 .ofEpochSecond(<时间戳(秒)>) /// 指定时区, ZoneOffset.ofHours(8) 是指时区对于 UTC 增加多少个小时 .atZone(ZoneOffset.ofHours(8)) /// 转成 LocalDateTime .toLocalDateTime(); Instant.ofEpochMilli(<时间戳(毫秒)>) /// 秒:Integer, 毫秒: Long /// 如果 Instant 要转成 LocalDate 或者 LocalDateTime 需要先通过 atZone 处理时区
PHP:
$date="2021-10-12"; echo strtotime($date); // output: 1633968000(秒,UTC时间) // 如果要转成北京时间,需要时区 +8



