Day.js

Day.js

  • Docs
  • GitHub
  • Languages iconEnglish
    • 中文
    • Русский
    • Español
    • Help Translate

›Plugins

Installation

  • Installation
  • Node.js
  • Browser
  • TypeScript
  • Download

Parse

  • Parse
  • Now
  • String
  • String + Format
  • Unix Timestamp (milliseconds)
  • Unix Timestamp (seconds)
  • Date
  • Object
  • Array
  • UTC
  • Dayjs Clone
  • Validation

Get + Set

  • Get + Set
  • Millisecond
  • Second
  • Minute
  • Hour
  • Date of Month
  • Day of Week
  • Day of Week (Locale Aware)
  • ISO Day of Week
  • Day of Year
  • Week of Year
  • Week of Year (ISO)
  • Month
  • Quarter
  • Year
  • Week Year
  • Week Year (ISO)
  • Weeks In Year (ISO)
  • Get
  • Set
  • Maximum
  • Minimum

Manipulate

  • Manipulate
  • Add
  • Subtract
  • Start of Time
  • End of Time
  • Local
  • UTC
  • UTC offset

Display

  • Display
  • Format
  • Time from now
  • Time from X
  • Time to now
  • Time to X
  • Calendar Time
  • Difference
  • Unix Timestamp (milliseconds)
  • Unix Timestamp
  • Days in Month
  • As Javascript Date
  • As Array
  • As JSON
  • As ISO 8601 String
  • As Object
  • As String

Query

  • Query
  • Is Before
  • Is Same
  • Is After
  • Is Same or Before
  • Is Same or After
  • Is Between
  • Is a Dayjs
  • Is Leap Year

i18n

  • i18n
  • Loading locale in NodeJS
  • Loading locale in the browser
  • Changing locale globally
  • Changing locales locally
  • Checking the current Day.js locale
  • Listing the months and weekdays of the current locale
  • Accessing locale specific functionality

Plugins

  • Plugin
  • Loading plugin in NodeJS
  • Loading plugin in the browser
  • AdvancedFormat
  • ArraySupport
  • BadMutable
  • BigIntSupport
  • BuddhistEra
  • Calendar
  • CustomParseFormat
  • DayOfYear
  • DevHelper
  • Duration
  • IsBetween
  • IsLeapYear
  • IsSameOrAfter
  • IsSameOrBefore
  • IsToday
  • IsTomorrow
  • IsYesterday
  • IsoWeek
  • IsoWeeksInYear
  • LocaleData
  • LocalizedFormat
  • MinMax
  • ObjectSupport
  • PluralGetSet
  • PreParsePostFormat
  • QuarterOfYear
  • RelativeTime
  • Timezone
  • ToArray
  • ToObject
  • UpdateLocale
  • UTC
  • weekOfYear
  • WeekYear
  • Weekday

Customize

  • Customize
  • Month Names
  • Month Abbreviations
  • Weekday Names
  • Weekday Abbreviations
  • Minimal Weekday Abbreviations
  • Relative Time
  • Calendar

Durations

  • Durations
  • Creating
  • Clone
  • Humanize
  • Format
  • Milliseconds
  • Seconds
  • Minutes
  • Hours
  • Days
  • Weeks
  • Months
  • Years
  • Add Time
  • Subtract Time
  • Using Duration with Diff
  • As Unit of Time
  • Get Unit of Time
  • As JSON
  • Is a Duration
  • As ISO 8601 String
  • Locale

Time Zone

  • Time Zone
  • Parsing in Zone
  • Converting to Zone
  • Guessing user zone
  • Set Default Timezone
Edit

Timezone

Timezone adds dayjs.tz .tz .tz.guess .tz.setDefault APIs to parse or display between time zones.

var utc = require("dayjs/plugin/utc");
// import utc from 'dayjs/plugin/utc' // ES 2015

var timezone = require("dayjs/plugin/timezone"); // dependent on utc plugin
// import timezone from 'dayjs/plugin/timezone' // ES 2015

dayjs.extend(utc);
dayjs.extend(timezone);

const timestamp = "2014-06-01 12:00";
const tz = "America/New_York";

const dayjsLocal = dayjs(timestamp); //assumes UTC
//dayjsLocal.toISOString() -> 2014-06-01T12:00:00.000Z
//dayjsLocal.format('YYYY-MM-DDTHH:mm:ss') -> 2014-06-01T12:00:00

const dayjsAmerica = dayjsLocal.tz(tz); //existing time treated as UTC
//dayjsAmerica.toISOString() -> 2014-06-01T12:00:00.000Z
//dayjsAmerica.format('YYYY-MM-DDTHH:mm:ss') -> 2014-06-01T08:00:00

const dayjsAmericaKeep = dayjsLocal.tz(tz, true); //existing time treated as local time
//dayjsAmericaKeep.toISOString() -> 2014-06-01T16:00:00.000Z
//dayjsAmericaKeep.format('YYYY-MM-DDTHH:mm:ss') -> 2014-06-01T12:00:00

Guessing the user timezone

dayjs.tz.guess();

Parsing in a timezone

const d1 = dayjs.tz("2013-11-18 11:55", "Asia/Taipei");
d1.format(); // => 2013-11-18T11:55:00+08:00
d1.toISOString(); // => 2013-11-18T03:55:00.000Z

Converting to a timezone

const d2 = dayjs.utc("2013-11-18 11:55").tz("Asia/Taipei");
d2.format(); // => 2013-11-18T19:55:00+08:00
d2.toISOString(); // => 2013-11-18T11:55:00.000Z

Set / reset the default timezone (used by 'tz')

// Setting the default timezone
dayjs.tz.setDefault("America/New_York");

// Resetting the default timezone to the system timezone
dayjs.tz.setDefault();

Differences to moment

Using the default timezone makes moment(dateValue) use this timezone (but moment.tz(dateValue, timezone) still requires the second parameter).

But dayjs(dateValue) always uses the local timezone, even if dayjs.tz.setDefault is used; only dayjs.tz(dateValue) (without second parameter) uses the default timezone.

← RelativeTimeToArray →
Day.js
Community
GitHubGitterSitemap
Copyright © 2025 Day.js