question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Abbreviated Timezone for IST/GMT+5:30

See original GitHub issue

When using the required plugins, the abbreviated timezone is not working for IST. With z, it shows GMT+5:30, but with zzz, it correctly shows Indian Standard Time.

import { Pipe, PipeTransform } from '@angular/core';
import * as dayjs from 'dayjs';
import * as advancedFormat from 'dayjs/plugin/advancedFormat';
import * as utc from 'dayjs/plugin/utc';
import * as timezone from 'dayjs/plugin/timezone';

@Pipe({
  name: 'dayjsTz'
})
export class DayJsDateTimePipe implements PipeTransform {
  public transform(value: Date, timeZone?: string, formatting = 'MMM Do YYYY, h:mm a z') {
    if (value) {
      dayjs.extend(advancedFormat);
      dayjs.extend(utc);
      dayjs.extend(timezone);
      if (timeZone) {
        return dayjs.tz(value, timeZone).format(formatting);
      }
      const userTimeZone = dayjs.tz.guess(); // here it guessed my timezone, Asia/Calcutta. I also tried hardcoding Asia/Kolkata, same result
      return dayjs.tz(value, userTimeZone).format(formatting);
    }
    return value;
  }
}

Current Output — Oct 20th 2020, 2:17 pm GMT+5:30 Expected Output — Oct 20th 2020, 2:17 pm IST

  • Day.js Version 1.9.3
  • OS: macOS Catalina 10.15.7
  • Browser Chrome 86 and Safari 14

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:15
  • Comments:18 (6 by maintainers)

github_iconTop GitHub Comments

7reactions
iamkuncommented, Oct 26, 2020

Seems a good choice. I’ll dig it more if I got some time.

6reactions
tanyaburlakovacommented, Mar 24, 2021

hello @iamkun

could you please let me know if this issue/feature is done or maybe in progress? In the doc I see it says we can use z for timezone abr https://day.js.org/docs/ru/plugin/advanced-format but it doesnt work.

Thank you!

Read more comments on GitHub >

github_iconTop Results From Across the Web

List of time zone abbreviations - Wikipedia
Abbr. Name UTC offset ACDT Australian Central Daylight Saving Time UTC+10:30 ACST Australian Central Standard Time UTC+09:30 ACT Acre Time UTC−05
Read more >
Time Zone Abbreviations - Worldwide List - Time and Date
Abbreviation Time zone name Location Offset A Alpha Time Zone Military UTC +1 ACT Acre Time South America UTC ‑5 ACT Australian Central Time Australia UTC...
Read more >
United States Time Zone Abbreviations
United States Time Zone Abbreviations with UTC/GMT Offsets ; AST, ATLANTIC STANDARD TIME, UTC - 4 ; EST, EASTERN STANDARD TIME, UTC -...
Read more >
Time Zone Abbreviations for Date and Time Functions
Abbreviation Full Name Registry ID ACDT Australian Central Daylight Time Cen. Australia Standard Time ACST Australian Central Standard Time AUS Central Standard Time AEDT Australian Eastern...
Read more >
HLC Time Zone Abbreviations - HealthStream
Abbreviation Description Central LiveMeeting ET (UTC‑05:00) Eastern Time (US & Canada) US/Eastern America/New York CT (UTC‑06:00) Central Time (US & Canada) US/Central America/Chicago MT (UTC‑07:00) Mountain...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found