vue中获取当前时间并格式化处理

day.js 封装公共js文件
/// <reference path="./locale/index.d.ts" />
export = dayjs;
declare function dayjs (date?: dayjs.ConfigType, option?: dayjs.OptionType, locale?: string): dayjs.Dayjs
declare namespace dayjs {
  export type ConfigType = string | number | Date | Dayjs
  export type OptionType = { locale?: string, format?: string, utc?: boolean } | string
  type UnitTypeShort = 'd' | 'M' | 'y' | 'h' | 'm' | 's' | 'ms'
  export type UnitType = 'millisecond' | 'second' | 'minute' | 'hour' | 'day' | 'month' | 'year' | 'date' | UnitTypeShort;
  export type OpUnitType = UnitType | "week" | 'w';
  export type QUnitType = UnitType | "quarter" | 'Q';
  class Dayjs {
    constructor (config?: ConfigType)
    clone(): Dayjs
    isValid(): boolean
    year(): number
    year(value: number): Dayjs
    month(): number
    month(value: number): Dayjs
    date(): number
    date(value: number): Dayjs
    day(): number
    day(value: number): Dayjs
    hour(): number
    hour(value: number): Dayjs
    minute(): number
    minute(value: number): Dayjs
    second(): number
    second(value: number): Dayjs
    millisecond(): number
    millisecond(value: number): Dayjs
    set(unit: UnitType, value: number): Dayjs
    get(unit: UnitType): number
    add(value: number, unit: OpUnitType): Dayjs
    subtract(value: number, unit: OpUnitType): Dayjs
    startOf(unit: OpUnitType): Dayjs
    endOf(unit: OpUnitType): Dayjs
    format(template?: string): string
    diff(date: ConfigType, unit?: QUnitType | OpUnitType, float?: boolean): number
    valueOf(): number
    unix(): number
    daysInMonth(): number
    toDate(): Date
    toJSON(): string
    toISOString(): string
   toString(): string
    utcOffset(): number
    isBefore(date: ConfigType, unit?: OpUnitType): boolean
    isSame(date: ConfigType, unit?: OpUnitType): boolean
    isAfter(date: ConfigType, unit?: OpUnitType): boolean
    locale(): string
    locale(preset: string | ILocale, object?: Partial<ILocale>): Dayjs
  }
  export type PluginFunc = (option: any, c: typeof Dayjs, d: typeof dayjs) => void
  export function extend(plugin: PluginFunc, option?: any): Dayjs
  export function locale(preset: string | ILocale, object?: Partial<ILocale>, isLocal?: boolean): string
  export function isDayjs(d: any): d is Dayjs
  export function unix(t: number): Dayjs
  const Ls : { [key: string] :  ILocale }
}

vue页面使用
// 获取当前时间并且时间格式化成  'YYYY-MM-DD'
  let nowTime = dayjs(new Date().toLocaleDateString()).format('YYYY-MM-DD')
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值