UNPKG

@kcuf/intl-formatter

Version:
20 lines (19 loc) 636 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = formatDate; var _util = require("./util"); /** * 格式化日期时间 * * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat */ function formatDate(date, format) { var locale = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'en-US'; try { return new Intl.DateTimeFormat(locale, (0, _util.getFormatDateOptions)(format)).format(date); } catch (_err) { return (0, _util.formatDateFallback)(date, (0, _util.getFormatDateFallbackPattern)(format)); } }