opened
MontoyaAndres
username_0
I'm using the function `format` to pass this date `2020-04-14T17:30:00.000Z` to the right format I'm using.

The database throws me this date, in ISO style `2020-04-14T17:30:00.000Z`, which is using this format to save it on the DB: 

`yyyy-MM-dd'T'HH:mm:ss.sss'Z'`

If I want to show this date on the browser, I use this function:

```
export function formatDate(date: string) {
  return format(new Date(date), "EEEE d MMM, h:mm aaaa");
}
```

It passes this `2020-04-14T17:30:00.000Z` to this `Tuesday 14 Apr, 5:30 p.m.` Which is right, it's what I want. This works perfectly on Windows and Android. But in IOS or Mac, the date `2020-04-14T17:30:00.000Z` is converted to `Tuesday 14 Apr, 12:30 p.m.`. Why happens this?

Thanks!
Date wrong on Iphone / Mac
issue
created
dkozickis
username_1
Are the timezones same on all of your devices?
comment
created
MontoyaAndres
username_0
I just get the date through the database, like for example:

2020-04-14T17:30:00.000Z

And I just concert it, using the function that I show before...
comment
created
dkozickis
username_1
That’s correct.

But you are initializing “new Date” on different clients, and when initialized this Date object gets time zone of the client where it was initialized. 

Hence the question - are time zones the same?
comment
created
MontoyaAndres
username_0
Oh I got it, no, in my case I'm from Colombia and the client is from Mexico, the client has the Mac and iPhone and he has that error
comment
created
MontoyaAndres
username_0
But the date it's static, I mean, it's always 2020-04-14T17:30:00.000Z the country affects something?
comment
created
dkozickis
username_1
See the “Z” at the end of date time strong means that this date time is in +0000 time zone.

1730Z is 1730 in GMT+0000, but is 2030 in GMT+0300. When you call `new Date` with this date, JS sees that there is a reference to time zone in the date time string and “converts” the provided date time to local time zone.


Try adding `X` (time zone) to the end of your format string, e.g. `EEEE d MMM, h:mm aaaa X` and see if output is different for you and your client.
comment
created
MontoyaAndres
username_0
I tried adding `EEEE d MMM, h:mm aaaa X` and the output is `Tuesday 14 Apr, 5:30 p.m. -05` in all the devices... What that `-05` mean?
comment
created
MontoyaAndres
username_0
One thing that I forgot to mention. It's when I call this method:

```
export function formatDate(date: string) {
  return format(new Date(date), "EEEE d MMM, h:mm aaaa");
}
```

I call this function like this: `formatDate(date.replace("Z", ""))` I remove the Z at the end because it gives me another date... Maybe the problem is how I save the date on ISO format...

This is because when the user opens the input of type="datetime-local" I take the value returned from the input and I format it to ISO like this:

````
import { format } from "date-fns";

const awsDateFormat = "yyyy-MM-dd'T'HH:mm:ss.sss'Z'";

export const formatDate = (date: string) =>
  format(new Date(date), awsDateFormat);
```

And the value returned from the variable `formatDate ` I save it to the db and then I do what I mentioned before... Maybe am I doing something wrong when I save the date when the user add it?
comment
created
MontoyaAndres
username_0
Yeah, I was saving the date wrongly to the db... Sorry about that :)
comment
closed
MontoyaAndres
username_0
issue
created
dkozickis
username_1
No prob :)
comment
created
RobSchilderr
username_2
saved my life
comment