Interface Time

Generator to generate time and date.

interface Time {
    date(format: string): string;
    dateRange(startdate: string, enddate: string, format: string): string;
    day(): number;
    futureTime(): string;
    hour(): number;
    minute(): number;
    month(): string;
    monthString(): string;
    nanosecond(): number;
    pastTime(): string;
    second(): number;
    timezone(): string;
    timezoneAbbreviation(): string;
    timezoneFull(): string;
    timezoneOffset(): number;
    timezoneRegion(): string;
    weekday(): string;
    year(): number;
}

Methods

  • Representation of a specific day, month, and year, often used for chronological reference.

    Parameters

    • format: string

      Format

    Returns string

    a random date

    import { Faker } from "k6/x/faker"

    let faker = new Faker(11)

    export default function () {
    console.log(faker.time.date("RFC3339"))
    }

    Output (formatted as JSON value)

    "2011-10-23T18:10:11Z"
    
  • Random date between two ranges.

    Parameters

    • startdate: string

      Start Date

    • enddate: string

      End Date

    • format: string

      Format

    Returns string

    a random daterange

    import { Faker } from "k6/x/faker"

    let faker = new Faker(11)

    export default function () {
    console.log(faker.time.dateRange("1970-01-01","2024-09-05","yyyy-MM-dd"))
    }

    Output (formatted as JSON value)

    "1988-03-03"
    
  • 24-hour period equivalent to one rotation of Earth on its axis.

    Returns number

    a random day

    import { Faker } from "k6/x/faker"

    let faker = new Faker(11)

    export default function () {
    console.log(faker.time.day())
    }

    Output (formatted as JSON value)

    22
    
  • Date that has occurred after the current moment in time.

    Returns string

    a random futuretime

    import { Faker } from "k6/x/faker"

    let faker = new Faker(11)

    export default function () {
    console.log(faker.time.futureTime())
    }

    Output (formatted as JSON value)

    "2024-09-05T22:35:15.223243185+02:00"
    
  • Unit of time equal to 60 minutes.

    Returns number

    a random hour

    import { Faker } from "k6/x/faker"

    let faker = new Faker(11)

    export default function () {
    console.log(faker.time.hour())
    }

    Output (formatted as JSON value)

    21
    
  • Unit of time equal to 60 seconds.

    Returns number

    a random minute

    import { Faker } from "k6/x/faker"

    let faker = new Faker(11)

    export default function () {
    console.log(faker.time.minute())
    }

    Output (formatted as JSON value)

    9
    
  • Division of the year, typically 30 or 31 days long.

    Returns string

    a random month

    import { Faker } from "k6/x/faker"

    let faker = new Faker(11)

    export default function () {
    console.log(faker.time.month())
    }

    Output (formatted as JSON value)

    10
    
  • String Representation of a month name.

    Returns string

    a random month string

    import { Faker } from "k6/x/faker"

    let faker = new Faker(11)

    export default function () {
    console.log(faker.time.monthString())
    }

    Output (formatted as JSON value)

    "October"
    
  • Unit of time equal to One billionth (10^-9) of a second.

    Returns number

    a random nanosecond

    import { Faker } from "k6/x/faker"

    let faker = new Faker(11)

    export default function () {
    console.log(faker.time.nanosecond())
    }

    Output (formatted as JSON value)

    953698829
    
  • Date that has occurred before the current moment in time.

    Returns string

    a random pasttime

    import { Faker } from "k6/x/faker"

    let faker = new Faker(11)

    export default function () {
    console.log(faker.time.pastTime())
    }

    Output (formatted as JSON value)

    "2024-09-05T02:35:15.223523755+02:00"
    
  • Unit of time equal to 1/60th of a minute.

    Returns number

    a random second

    import { Faker } from "k6/x/faker"

    let faker = new Faker(11)

    export default function () {
    console.log(faker.time.second())
    }

    Output (formatted as JSON value)

    9
    
  • Region where the same standard time is used, based on longitudinal divisions of the Earth.

    Returns string

    a random timezone

    import { Faker } from "k6/x/faker"

    let faker = new Faker(11)

    export default function () {
    console.log(faker.time.timezone())
    }

    Output (formatted as JSON value)

    "Tonga Standard Time"
    
  • Abbreviated 3-letter word of a timezone.

    Returns string

    a random timezone abbreviation

    import { Faker } from "k6/x/faker"

    let faker = new Faker(11)

    export default function () {
    console.log(faker.time.timezoneAbbreviation())
    }

    Output (formatted as JSON value)

    "TST"
    
  • Full name of a timezone.

    Returns string

    a random timezone full

    import { Faker } from "k6/x/faker"

    let faker = new Faker(11)

    export default function () {
    console.log(faker.time.timezoneFull())
    }

    Output (formatted as JSON value)

    "(UTC+13:00) Nuku'alofa"
    
  • The difference in hours from Coordinated Universal Time (UTC) for a specific region.

    Returns number

    a random timezone offset

    import { Faker } from "k6/x/faker"

    let faker = new Faker(11)

    export default function () {
    console.log(faker.time.timezoneOffset())
    }

    Output (formatted as JSON value)

    13
    
  • Geographic area sharing the same standard time.

    Returns string

    a random timezone region

    import { Faker } from "k6/x/faker"

    let faker = new Faker(11)

    export default function () {
    console.log(faker.time.timezoneRegion())
    }

    Output (formatted as JSON value)

    "Asia/Manila"
    
  • Day of the week excluding the weekend.

    Returns string

    a random weekday

    import { Faker } from "k6/x/faker"

    let faker = new Faker(11)

    export default function () {
    console.log(faker.time.weekday())
    }

    Output (formatted as JSON value)

    "Sunday"
    
  • Period of 365 days, the time Earth takes to orbit the Sun.

    Returns number

    a random year

    import { Faker } from "k6/x/faker"

    let faker = new Faker(11)

    export default function () {
    console.log(faker.time.year())
    }

    Output (formatted as JSON value)

    1979