Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PrimeNG Calendar <p-calendar> - How to disable UTC - Z timezone

Does anyone know if it's possible to disable the date/time picker from automatically adding the UTC time to the date object? As you can see in the below picture that it's automatically adjusting my date object to UTC. I want my date object submitted with 10:00:00

enter image description here

{"reportedDate": "2019-02-13T15:00:16.000Z"}


<p-calendar required [(ngModel)]="entry.reportedDate" name="reportedDate" #reportedDate="ngModel" [showIcon]="true" [showTime]="true" dateFormat="mm/dd/y 'EST'" hourFormat="24"></p-calendar>
like image 670
Rob DePietro Avatar asked Mar 04 '23 11:03

Rob DePietro


1 Answers

According to the documentation page for this component (in the properties table):

Name        Type      Default    Description
-----------------------------------------------------------------------------
dataType    string    date       Type of the value to write back to ngModel,
                                 default is date and alternative is string.

You should pass [dataType]="string". This will prevent a Date object from being constructed, which will in-turn prevent any time zone conversions.

Also, I recommend not putting a time zone abbreviation in the format for the entry. Keep in mind that daylight saving time might be in effect depending on the date chosen, and also that not every time zone has a clear and consistent abbreviation, and that some abbreviations (such as CST or IST) are ambiguous.

If you need to indicate to the user that the entry is in US Eastern Time, then put that somewhere outside of the textbox. If you must use an abbreviation, use ET as the generic form.

like image 176
Matt Johnson-Pint Avatar answered May 08 '23 16:05

Matt Johnson-Pint