import
java.time.Instant;
import
java.time.
LocalDate;
import
java.time.
LocalDateTime;
import
java.time.ZoneOffset;
import
java.time.format.
DateTimeFormatter;
import
java.util.
Date;
public class
DateUtils {
public static void main(String[] args) {
程序开发中,经常拿到字符串类型的时间,需要将他们转化为LocalDateTime时间,有时还需要获取13位的时间戳
public static void main(String[] args) {
String gpsTime= "2022-03-19 17:37:38.222";
DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS");
System.out.println(String.va
开发当中经常时间转换非常常见,最近的项目当中使用了LocalDateTime,特此记录下LocalDateTime的常用转换。
LocalDateTime和时间戳互转
* 获取到毫秒级时间戳
* @param localDateTime 具体时间
* @return long 毫秒级时间戳
public static long toEpochMilli(LocalDateTime localDateTime){
retur
//
LocalDateTime转时间戳
//获取秒数
long second =
LocalDateTime.now().toEpochSecond(ZoneOffset.of("+8"));
System.out.println(second);
//获取毫秒数
```
javascript
// 假设
字符串时间为 '2022-03-01 10:30:00'
const timestamp = new
Date('2022-03-01 10:30:00').getTime();
console.log(timestamp); // 输出:1646127000000
这里使用了
Date对象的getTime()方法来获取
时间戳,它返回从1970年1月1日午夜(UTC)开始计算的毫秒数。注意,如果
字符串时间格式不正确,或者
字符串中包含的
时间不符合当前时区的格式,将会导致
转换失败。
另外,如果要在Vue中使用
时间戳,可以在模板中使用过滤器或计算属性来将
时间戳
转换为可读格式。例如,可以使用以下过滤器将
时间戳
转换为年月日格式:
```
javascript
Vue.filter('format
Date', function(timestamp) {
const
date = new
Date(timestamp);
const year =
date.getFullYear();
const month =
date.getMonth() + 1;
const day =
date.get
Date();
return `${year}-${month}-${day}`;
然后在模板中使用:
```html
<p>{{ timestamp | format
Date }}</p>
其中,timestamp为
时间戳。
maven发布deploy时repository element was not specified in the POM inside distributionManagement element