Momentjs utc() working differently on local (Mac) and server (Ubuntu)
up vote
0
down vote
favorite
Trying to figure out if this is an actual bug or a fundamental gap in understanding moment.js utc() method on my part.
When the method is used to convert an existing time/date string it returns an incorrect result on Ubuntu only
using moment@2.22.2
On Ubuntu 16.04.4 LTS
> moment().utc().format()
'2018-11-10T16:30:28Z'
> moment('2018-11-13 19:00:00').utc().format()
'2018-11-13T19:00:00Z'
On Mac OsX 10.13.2
> moment().utc().format()
'2018-11-10T16:29:24Z'
> moment('2018-11-13 19:00:00').utc().format()
'2018-11-14T00:00:00Z'
javascript momentjs
add a comment |
up vote
0
down vote
favorite
Trying to figure out if this is an actual bug or a fundamental gap in understanding moment.js utc() method on my part.
When the method is used to convert an existing time/date string it returns an incorrect result on Ubuntu only
using moment@2.22.2
On Ubuntu 16.04.4 LTS
> moment().utc().format()
'2018-11-10T16:30:28Z'
> moment('2018-11-13 19:00:00').utc().format()
'2018-11-13T19:00:00Z'
On Mac OsX 10.13.2
> moment().utc().format()
'2018-11-10T16:29:24Z'
> moment('2018-11-13 19:00:00').utc().format()
'2018-11-14T00:00:00Z'
javascript momentjs
Should use the format argument ofmoment(input, format)
when you use a non standard ISO date string
– charlietfl
Nov 10 at 17:06
thnk u but unfortunately, format option doesn't solve this problem
– dima
Nov 10 at 17:40
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
Trying to figure out if this is an actual bug or a fundamental gap in understanding moment.js utc() method on my part.
When the method is used to convert an existing time/date string it returns an incorrect result on Ubuntu only
using moment@2.22.2
On Ubuntu 16.04.4 LTS
> moment().utc().format()
'2018-11-10T16:30:28Z'
> moment('2018-11-13 19:00:00').utc().format()
'2018-11-13T19:00:00Z'
On Mac OsX 10.13.2
> moment().utc().format()
'2018-11-10T16:29:24Z'
> moment('2018-11-13 19:00:00').utc().format()
'2018-11-14T00:00:00Z'
javascript momentjs
Trying to figure out if this is an actual bug or a fundamental gap in understanding moment.js utc() method on my part.
When the method is used to convert an existing time/date string it returns an incorrect result on Ubuntu only
using moment@2.22.2
On Ubuntu 16.04.4 LTS
> moment().utc().format()
'2018-11-10T16:30:28Z'
> moment('2018-11-13 19:00:00').utc().format()
'2018-11-13T19:00:00Z'
On Mac OsX 10.13.2
> moment().utc().format()
'2018-11-10T16:29:24Z'
> moment('2018-11-13 19:00:00').utc().format()
'2018-11-14T00:00:00Z'
javascript momentjs
javascript momentjs
edited Nov 10 at 18:11
asked Nov 10 at 16:57
dima
55557
55557
Should use the format argument ofmoment(input, format)
when you use a non standard ISO date string
– charlietfl
Nov 10 at 17:06
thnk u but unfortunately, format option doesn't solve this problem
– dima
Nov 10 at 17:40
add a comment |
Should use the format argument ofmoment(input, format)
when you use a non standard ISO date string
– charlietfl
Nov 10 at 17:06
thnk u but unfortunately, format option doesn't solve this problem
– dima
Nov 10 at 17:40
Should use the format argument of
moment(input, format)
when you use a non standard ISO date string– charlietfl
Nov 10 at 17:06
Should use the format argument of
moment(input, format)
when you use a non standard ISO date string– charlietfl
Nov 10 at 17:06
thnk u but unfortunately, format option doesn't solve this problem
– dima
Nov 10 at 17:40
thnk u but unfortunately, format option doesn't solve this problem
– dima
Nov 10 at 17:40
add a comment |
2 Answers
2
active
oldest
votes
up vote
1
down vote
accepted
Moment interprets your string as a local time. Your Ubuntu machine's time zone is set to UTC, so it reads "2018-11-13 19:00:00" as a UTC time, and converting it to UTC in your code is a noop. Your Mac is on your local time, so it interprets the string as having been expressed in whatever time zone you're in, and then utc()
translates it to UTC time. So you get different results.
If you want Moment to know that the string is expressed in UTC, you need to tell it that, for example by using ISO's "Z" (e.g. '2018-11-13T19:00:00Z') or by using moment.utc("2018-11-13 19:00:00", format)
add a comment |
up vote
0
down vote
Try to provide the format in which data string is
console.log(moment('2018-11-13 19:00:00','YYYY-MM-DD h:mm:ss').utc().format())
Unfortunately, the same behavior persists. Correct date/time on Mac and Ubuntu just passing a date/time through
– dima
Nov 10 at 17:38
Which platform it shown different behaviour
– front_end_dev
Nov 10 at 17:42
ubuntu is still returning the same date/time > console.log(moment('2018-11-13 19:00:00','YYYY-MM-DD h:mm:ss').utc().format()) 2018-11-13T19:00:00Z
– dima
Nov 10 at 17:57
@dima Didn't have ubuntu unable to debug this.
– front_end_dev
Nov 10 at 18:00
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
Moment interprets your string as a local time. Your Ubuntu machine's time zone is set to UTC, so it reads "2018-11-13 19:00:00" as a UTC time, and converting it to UTC in your code is a noop. Your Mac is on your local time, so it interprets the string as having been expressed in whatever time zone you're in, and then utc()
translates it to UTC time. So you get different results.
If you want Moment to know that the string is expressed in UTC, you need to tell it that, for example by using ISO's "Z" (e.g. '2018-11-13T19:00:00Z') or by using moment.utc("2018-11-13 19:00:00", format)
add a comment |
up vote
1
down vote
accepted
Moment interprets your string as a local time. Your Ubuntu machine's time zone is set to UTC, so it reads "2018-11-13 19:00:00" as a UTC time, and converting it to UTC in your code is a noop. Your Mac is on your local time, so it interprets the string as having been expressed in whatever time zone you're in, and then utc()
translates it to UTC time. So you get different results.
If you want Moment to know that the string is expressed in UTC, you need to tell it that, for example by using ISO's "Z" (e.g. '2018-11-13T19:00:00Z') or by using moment.utc("2018-11-13 19:00:00", format)
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
Moment interprets your string as a local time. Your Ubuntu machine's time zone is set to UTC, so it reads "2018-11-13 19:00:00" as a UTC time, and converting it to UTC in your code is a noop. Your Mac is on your local time, so it interprets the string as having been expressed in whatever time zone you're in, and then utc()
translates it to UTC time. So you get different results.
If you want Moment to know that the string is expressed in UTC, you need to tell it that, for example by using ISO's "Z" (e.g. '2018-11-13T19:00:00Z') or by using moment.utc("2018-11-13 19:00:00", format)
Moment interprets your string as a local time. Your Ubuntu machine's time zone is set to UTC, so it reads "2018-11-13 19:00:00" as a UTC time, and converting it to UTC in your code is a noop. Your Mac is on your local time, so it interprets the string as having been expressed in whatever time zone you're in, and then utc()
translates it to UTC time. So you get different results.
If you want Moment to know that the string is expressed in UTC, you need to tell it that, for example by using ISO's "Z" (e.g. '2018-11-13T19:00:00Z') or by using moment.utc("2018-11-13 19:00:00", format)
answered Nov 12 at 15:03
snickersnack
1463
1463
add a comment |
add a comment |
up vote
0
down vote
Try to provide the format in which data string is
console.log(moment('2018-11-13 19:00:00','YYYY-MM-DD h:mm:ss').utc().format())
Unfortunately, the same behavior persists. Correct date/time on Mac and Ubuntu just passing a date/time through
– dima
Nov 10 at 17:38
Which platform it shown different behaviour
– front_end_dev
Nov 10 at 17:42
ubuntu is still returning the same date/time > console.log(moment('2018-11-13 19:00:00','YYYY-MM-DD h:mm:ss').utc().format()) 2018-11-13T19:00:00Z
– dima
Nov 10 at 17:57
@dima Didn't have ubuntu unable to debug this.
– front_end_dev
Nov 10 at 18:00
add a comment |
up vote
0
down vote
Try to provide the format in which data string is
console.log(moment('2018-11-13 19:00:00','YYYY-MM-DD h:mm:ss').utc().format())
Unfortunately, the same behavior persists. Correct date/time on Mac and Ubuntu just passing a date/time through
– dima
Nov 10 at 17:38
Which platform it shown different behaviour
– front_end_dev
Nov 10 at 17:42
ubuntu is still returning the same date/time > console.log(moment('2018-11-13 19:00:00','YYYY-MM-DD h:mm:ss').utc().format()) 2018-11-13T19:00:00Z
– dima
Nov 10 at 17:57
@dima Didn't have ubuntu unable to debug this.
– front_end_dev
Nov 10 at 18:00
add a comment |
up vote
0
down vote
up vote
0
down vote
Try to provide the format in which data string is
console.log(moment('2018-11-13 19:00:00','YYYY-MM-DD h:mm:ss').utc().format())
Try to provide the format in which data string is
console.log(moment('2018-11-13 19:00:00','YYYY-MM-DD h:mm:ss').utc().format())
answered Nov 10 at 17:16
front_end_dev
1,310411
1,310411
Unfortunately, the same behavior persists. Correct date/time on Mac and Ubuntu just passing a date/time through
– dima
Nov 10 at 17:38
Which platform it shown different behaviour
– front_end_dev
Nov 10 at 17:42
ubuntu is still returning the same date/time > console.log(moment('2018-11-13 19:00:00','YYYY-MM-DD h:mm:ss').utc().format()) 2018-11-13T19:00:00Z
– dima
Nov 10 at 17:57
@dima Didn't have ubuntu unable to debug this.
– front_end_dev
Nov 10 at 18:00
add a comment |
Unfortunately, the same behavior persists. Correct date/time on Mac and Ubuntu just passing a date/time through
– dima
Nov 10 at 17:38
Which platform it shown different behaviour
– front_end_dev
Nov 10 at 17:42
ubuntu is still returning the same date/time > console.log(moment('2018-11-13 19:00:00','YYYY-MM-DD h:mm:ss').utc().format()) 2018-11-13T19:00:00Z
– dima
Nov 10 at 17:57
@dima Didn't have ubuntu unable to debug this.
– front_end_dev
Nov 10 at 18:00
Unfortunately, the same behavior persists. Correct date/time on Mac and Ubuntu just passing a date/time through
– dima
Nov 10 at 17:38
Unfortunately, the same behavior persists. Correct date/time on Mac and Ubuntu just passing a date/time through
– dima
Nov 10 at 17:38
Which platform it shown different behaviour
– front_end_dev
Nov 10 at 17:42
Which platform it shown different behaviour
– front_end_dev
Nov 10 at 17:42
ubuntu is still returning the same date/time > console.log(moment('2018-11-13 19:00:00','YYYY-MM-DD h:mm:ss').utc().format()) 2018-11-13T19:00:00Z
– dima
Nov 10 at 17:57
ubuntu is still returning the same date/time > console.log(moment('2018-11-13 19:00:00','YYYY-MM-DD h:mm:ss').utc().format()) 2018-11-13T19:00:00Z
– dima
Nov 10 at 17:57
@dima Didn't have ubuntu unable to debug this.
– front_end_dev
Nov 10 at 18:00
@dima Didn't have ubuntu unable to debug this.
– front_end_dev
Nov 10 at 18:00
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53241248%2fmomentjs-utc-working-differently-on-local-mac-and-server-ubuntu%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Should use the format argument of
moment(input, format)
when you use a non standard ISO date string– charlietfl
Nov 10 at 17:06
thnk u but unfortunately, format option doesn't solve this problem
– dima
Nov 10 at 17:40