當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


JavaScript ArcGIS intl.convertDateFormatToIntlOptions用法及代碼示例

基本信息

以下是所在類或對象的基本信息。

AMD: require(["esri/intl"], (intl) => { /* code goes here */ });

ESM: import * as intl from "@arcgis/core/intl";

對象: esri/intl

自從:用於 JavaScript 4.12 的 ArcGIS API

用法說明

intl.convertDateFormatToIntlOptions函數(或屬性)的定義如下:

convertDateFormatToIntlOptions (format) {Intl.DateTimeFormatOptions}


web map date format string 轉換為 Intl.DateTimeFormat 選項對象。

參數:

類型說明
format String
可選的

要轉換的 web Map日期格式字符串。

可能的值"short-date"|"short-date-short-time"|"short-date-short-time-24"|"short-date-long-time"|"short-date-long-time-24"|"long-month-day-year"|"long-month-day-year-short-time"|"long-month-day-year-short-time-24"|"long-month-day-year-long-time"|"long-month-day-year-long-time-24"|"day-short-month-year"|"day-short-month-year-short-time"|"day-short-month-year-short-time-24"|"day-short-month-year-long-time"|"day-short-month-year-long-time-24"|"long-date"|"long-date-short-time"|"long-date-short-time-24"|"long-date-long-time"|"long-date-long-time-24"|"long-month-year"|"short-month-year"|"year"|"short-time"|"long-time"

返回:

類型 說明
Intl.DateTimeFormatOptions 從 web Map規範中定義的格式字符串派生的日期格式選項。

例子:

const dateFormatIntlOptions = intl.convertDateFormatToIntlOptions("short-date-short-time");

// See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat#Parameters
// Setting the string value 'short-date-short-time' is similar to what is set in the object below
// dateFormatIntlOptions = {
//   day: "numeric",
//   month: "numeric",
//   year: "numeric",
//   hour: "numeric",
//   minute: "numeric"
// }

const now = Date.now(); // 1560375191812
const formattedDate = intl.formatDate(now, dateFormatIntlOptions);

console.log(formattedDate); // expected output for US English locale: "6/12/2019, 2:33 PM"

相關用法


注:本文由純淨天空篩選整理自arcgis.com大神的英文原創作品 intl.convertDateFormatToIntlOptions。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。