本文整理匯總了TypeScript中dayjs類的典型用法代碼示例。如果您正苦於以下問題:TypeScript dayjs類的具體用法?TypeScript dayjs怎麽用?TypeScript dayjs使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了dayjs類的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: toFormatter
export function toFormatter(date: Date): DateFormatter {
const wrappedDate = dayjs(date);
return {
fromNow: () => wrappedDate.fromNow(),
format: (format: string) => wrappedDate.format(format)
};
}
示例2: dayjs
gulp.task('clean:version-lib', (next) => {
const v = npmconfig.version;
const b = dayjs().startOf('m').valueOf();
return gulp.src(['./lib/src/composer.module.ts']) // Any file globs are supported
.pipe(replace(/public static version = '[0-9a-zA-Z.-]*'/g, `public static version = 'local-dev'`, { logs: { enabled: true } }))
.pipe(replace(/private build = dayjs\([0-9]*\);/g, `private build = dayjs();`, { logs: { enabled: true } }))
.pipe(gulp.dest('./lib/src'));
});
示例3: dayjs
export const downloadJSON = (panelName, modelName, endpoint) => {
const timestamp = dayjs(Date.now()).format('DD_MM_YYYY_HH_mm_ss');
return api.get(endpoint).then((res) => {
const content = JSON.stringify(res.data, null, 2);
const a = document.createElement('a');
const file = new Blob([content]);
a.href = URL.createObjectURL(file);
a.download = `${modelName}_${timestamp}_${panelName}.json`;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
});
};
示例4: reviver
export function reviver(key, value) {
if (typeof value === 'string')
if (ISO8601Regex.exec(value))
return dayjs(value).toDate();
return value;
}
示例5: replacer
export function replacer(key, value) {
if (typeof value === 'string')
if (ISO8601Regex.exec(value))
return dayjs(value).format("YYYY-MM-DDTHH:mm:ss.SSSZ");
return value;
}
示例6: getFormatter
export function getFormatter(date: Date): DateFormatter {
return dayjs(date);
}