0

I'm working in Typescript and I am getting a Date object from data and expected to put a Date object back.

The Date object is adjusting for timezone and that is NOT behavior that I want...I just want the Date that I was given to use and be able to pass that around and put it back.

    dateString = Tue Jun 02 2020 00:00:00 GMT+1030 (Lord Howe Standard Time)
    const dateOptions = {timeZone: 'America/Chicago', month: 'numeric', day: 'numeric', year: 
    'numeric'};
    const dateFormatter = new Intl.DateTimeFormat('en-US', dateOptions);
    const offset = Math.abs(dateString.getTimezoneOffset() / 60) ;
    const offSetDate = new Date(dateString);
    offSetDate.setHours(0,0,0,0);
    offSetDate.setDate(day);
    
    const dateAsFormattedString = dateFormatter.format(offSetDate);

This returns "6/1/2020" not "6/2/2020" how can I just use the date I need as a date and ignore timezone? Sorry for all the code, I feel like I've tried everything...why is this so hard?

Any help is greatly appreciated!!

Funn_Bobby
  • 647
  • 1
  • 20
  • 57
  • See the [Date Pipe documentation](https://angular.io/api/common/DatePipe). There are various things you could do like ensure the date time instance is UTC (+0) for the time zone and then supply `UTC` for the `timezone` argument of the date pipe. You could also supply the source time zone of the date instance back to the `timezone` argument. – Igor Aug 18 '20 at 18:31
  • The date is just the epoch timestamp in milliseconds. Have a look at this: https://stackoverflow.com/questions/17545708/parse-date-without-timezone-javascript – Stefan Aug 18 '20 at 18:40
  • Neither of these suggestions have worked so far...I get "Mon, 01 Jun 2020 03:30:00 GMT" returned for "Tue Jun 02 2020 00:00:00 GMT+1030" when using a timezone outside the US – Funn_Bobby Aug 18 '20 at 19:17

0 Answers0