From d772272787cea8bda32173ad3665ab1abe792f59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=9C=E5=BA=86=E6=B3=89?= Date: Fri, 1 Mar 2024 16:33:18 +0800 Subject: [PATCH] Update data-type.md --- docs/uts/data-type.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/docs/uts/data-type.md b/docs/uts/data-type.md index f4582ce2..942fbbef 100644 --- a/docs/uts/data-type.md +++ b/docs/uts/data-type.md @@ -646,6 +646,28 @@ const year:number = myDate.getFullYear() Date对象还有很多方法属性,[详见](buildin-object-api/date.md) +#### 与平台日期对象的转换 + +如果需要将`Date` 与java平台自带的`java.util.Date`转换,建议使用时间戳作为关键参数进行转换处理: + ++ Date 转 java.util.Date + +```uts +import JavaDate from 'java.util.Date' ; + +let utsDate = Date("1998-02-02 01:03:01") +let javaDate = JavaDate(utsDate.getTime().toLong()) +``` + ++ java.util.Date 转 Date +```uts +import JavaDate from 'java.util.Date' ; + +let javaDate = JavaDate(1709208329000) +let utsDate = Date(javaDate2.getTime()) +``` + + ## 数组(Array)@array -- GitLab