1

I am using below code to convert timestamp to date

import { DatePipe } from '@angular/common';

constructor(private pipe: DatePipe) {
}

dateConverter(timestampDate: any) {
if (timestampDate.toString().indexOf('.') > 0) {
  return this.pipe.transform(new Date(timestampDate* 1000), 'dd-MMM-y');
} else {
  timestampDate= timestampDate.toString() + '.0000';
  return this.pipe.transform(new Date(timestampDate* 1000), 'dd-MMM-y');
}

}

Here how can I convert timestamp to Date without considering the timezone.

For example timestampDate value 1451932200

Shiny
  • 127
  • 1
  • 6
  • 12
  • Add .toUTCString() when creating new Date(), thanks to [this](https://stackoverflow.com/questions/17545708/parse-date-without-timezone-javascript) – Gregor Albert Jan 29 '19 at 07:50
  • It is not working getting error like "Unable to convert "Invalid Date" into a date' for pipe 'DatePipe' " - @GregorAlbert – Shiny Jan 29 '19 at 08:54

1 Answers1

1

Do you think this will work for you?

(new Date(timestampDate)).toUTCString()

Vibhanshu Biswas
  • 379
  • 1
  • 15
  • It is not working getting error like "Unable to convert "Invalid Date" into a date' for pipe 'DatePipe' " - @Vibhanshu Biswas – Shiny Jan 29 '19 at 08:54
  • It worked in this way new Date(timestampDate* 1000).toUTCString - @Vibhanshu Biswas – Shiny Jan 29 '19 at 09:00