@alicloud/console-base-intl-factory-basic
Version:
ConsoleBase Intl Factory Basic, Pure Text, No JSX
17 lines (16 loc) • 676 B
JavaScript
import formatDateFallback from './format-date-fallback';
import getFormatDateFallbackPattern from './get-format-date-fallback-pattern';
import getFormatDateOptions from './get-format-date-options';
/**
* 格式化日期时间
*
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat
*/
export default function formatDate(date, format) {
var locale = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'en-US';
try {
return new Intl.DateTimeFormat(locale, getFormatDateOptions(format)).format(date);
} catch (err) {
return formatDateFallback(date, getFormatDateFallbackPattern(format));
}
}