Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface Datefromat

Hierarchy

  • Datefromat

Index

Methods

cloneDate

  • cloneDate(val: Date): Date
  • Parameters

    • val: Date

      需要深拷贝的原始时间对象

    Returns Date

    新的时间对象

    utils.cloneDate(new Date('2012-11-21'))

formatDate

  • formatDate(d: Date | string | number, type?: undefined | string): string
  • Parameters

    • d: Date | string | number

      传入时间

    • Optional type: undefined | string

      需要转化为什么格式

    Returns string

    formatDate()  "2017-03-28"
    formatDate(new Date(), 'datetime') "2017-03-15 15:34"

formatEffectiveDate

  • formatEffectiveDate(date?: any): Date
  • Parameters

    • Optional date: any

      需要判断格式是否正确的日期

    Returns Date

    返回正确的当前时间对象

formatHourTime

  • formatHourTime(value: number, hour?: undefined | false | true): string
  • 格式化时间 支持自定义格式 参考element-ui的时间格式

    author

    Jarvan

    utils.formatHourTime(1587823200000, true)    // '2020-04-25 22:00:00'
    utils.formatHourTime(1587823200000)    // '2020-04-25'

    Parameters

    • value: number

      传入时间戳 10位 | 13位

    • Optional hour: undefined | false | true

      可选参数 是否需要小时、分钟、秒钟

    Returns string

    '2020-04-25 22:00:00'

formatSecond

  • formatSecond(s: number): string
  • 将秒数转为HH:MM:SS格式

    Parameters

    • s: number

      :秒数,不是毫秒

    Returns string

formatTime

  • formatTime(value: number, format?: undefined | string): string
  • 格式化时间 支持自定义格式 参考element-ui的时间格式

    author

    Jarvan

    格式 含义 备注 举例
    yy 20
    yyyy 2020
    M 不补0 5
    MM 05
    d 不补0 1
    dd 01
    D 一周第几天 周日-周六(0 - 6) 不补0 3
    DD 03
    h 小时 12小时制,须和 A 或 a 使用;不补0 9
    hh 小时 12小时制,须和 A 或 a 使用 09
    H 小时 24小时制;不补0 3
    HH 小时 24小时制 03
    m 不补0 4
    mm 04
    s 不补0 05
    ss 05
    a am/pm am
    A AM/PM AM
    utils.formatTime(1587823200000, 'yyyy-MM-dd HH:mm:ss')    // '2020-04-25 22:00:00'
    utils.formatTime(1587823200000, 'yyyy-MM-dd')    // '2020-04-25'
    utils.formatTime(1587823200, 'yyyy-M-d')    // '2020-4-25'

    Parameters

    • value: number

      传入时间戳 10位 | 13位

    • Optional format: undefined | string

      可选参数 传入目标时间格式 默认'yyyy-MM-dd HH:mm:ss'

    Returns string

    '2020-04-25 22:00:00'

formatTimeCompare

  • formatTimeCompare(time?: number | string): string | void
  • 与现在时间做比较

    Parameters

    • Optional time: number | string

      需要比较的时间(秒)

    Returns string | void

    1分钟内: '刚刚'
    1小时内: 'xx分钟前'
    5小时内: 'xx小时前'
    超过5小时但在今日内: '今日 hh:mm'
    其他时间:'DD-MM hh:mm'

getDay

  • getDay(addDayCount: number, appointedDate: number | string | Date, type?: undefined | string): string
  • 获取指定日期前后n天的日期,如果没有指定日期,则是当前日期n天的前后

    Parameters

    • addDayCount: number

      前后n天

    • appointedDate: number | string | Date

      指定日期

    • Optional type: undefined | string

      返回时间类型,可选

    Returns string

getMonthDay

  • getMonthDay(monthNum: number, appointedDate: string | number | Date, type?: undefined | string): string
  • 获取指定日期前后n个月的日期,如果没有指定日期,则是当前日期的前后n个月

    Parameters

    • monthNum: number

      前后n月

    • appointedDate: string | number | Date

      指定日期

    • Optional type: undefined | string

      返回时间类型,可选

    Returns string

getYearDay

  • getYearDay(addYearCount: number, appointedDate: any, type?: undefined | string): string
  • 获取指定日期前后n年的日期,如果没有指定日期,则是当前日期n年的前后

    Parameters

    • addYearCount: number

      前后的n年

    • appointedDate: any

      指定日期

    • Optional type: undefined | string

      返回日期格式

    Returns string

now

  • now(long?: undefined | false | true): string
  • 返回当前系统时间

    author

    Jarvan

    utils.now()      // 1587823200
    utils.now(true)  // 1587823200000

    Parameters

    • Optional long: undefined | false | true

      是否需要 10位或者13位时间戳 默认为 10位时间戳

    Returns string

    '1587823200'

timeToTimestamp

  • timeToTimestamp(time: string): string | number
  • 将日期转换为时间戳的格式

    Parameters

    • time: string

    Returns string | number

timeZone

  • timeZone(time: Date): Date
  • Parameters

    • time: Date

      需要转化的时间

    Returns Date

    格林尼治时间对象

    utils.timeZone(new Date('2012-12-21'))

timestampToTime

  • timestampToTime<T>(timestamp: T): object | T
  • 将时间戳转换为日期格式

    Type parameters

    • T

    Parameters

    • timestamp: T

    Returns object | T

timestampToTimeString

  • timestampToTimeString(timestamp: string | number, type: string): string
  • description:

    将时间戳转成指定的格式

    Parameters

    • timestamp: string | number

      时间戳

    • type: string

      :'yyyy-MM-dd HH:mm', 'yyyy-MM-dd' 这两种格式

    Returns string

Generated using TypeDoc