Serialize / Deserialize UTC DateTimes before 01-01-1970
I am having the following problem. If I serialize Dates since 01-01-1970 and I deserialize them it works as expected. But for dates before 01-01-1970 the deserialization with momentjs doesn't work.
DateTime dt = new DateTime(2010, 10, 20);
DateTimeOffset dt2 = new DateTimeOffset(dt).ToUniversalTime();
long a = dt2.ToUnixTimeMilliseconds();
Console.WriteLine("value1: " + a); //1287525600000 => moment(1287525600000).toDate() => Wednesday, 20. October 2010 (00:00:00)
DateTime dtfoo = new DateTime(1962, 10, 20);
DateTimeOffset dtfoo2 = new DateTimeOffset(dtfoo).ToUniversalTime();
long afoo = dtfoo2.ToUnixTimeMilliseconds();
Console.WriteLine("value2: " + afoo); // -227239200000 => moment(-227239200000).toDate() => Friday, 19. October 1962 (23:00:00 GMT+01:00)
Console.ReadLine();
I am deserializing the dates just with moment(unixtime).toDate()
. The first date is 20-10-2010. The second date is 19-10-1962 (instead 20-10-1962).
c# datetime momentjs utc
add a comment |
I am having the following problem. If I serialize Dates since 01-01-1970 and I deserialize them it works as expected. But for dates before 01-01-1970 the deserialization with momentjs doesn't work.
DateTime dt = new DateTime(2010, 10, 20);
DateTimeOffset dt2 = new DateTimeOffset(dt).ToUniversalTime();
long a = dt2.ToUnixTimeMilliseconds();
Console.WriteLine("value1: " + a); //1287525600000 => moment(1287525600000).toDate() => Wednesday, 20. October 2010 (00:00:00)
DateTime dtfoo = new DateTime(1962, 10, 20);
DateTimeOffset dtfoo2 = new DateTimeOffset(dtfoo).ToUniversalTime();
long afoo = dtfoo2.ToUnixTimeMilliseconds();
Console.WriteLine("value2: " + afoo); // -227239200000 => moment(-227239200000).toDate() => Friday, 19. October 1962 (23:00:00 GMT+01:00)
Console.ReadLine();
I am deserializing the dates just with moment(unixtime).toDate()
. The first date is 20-10-2010. The second date is 19-10-1962 (instead 20-10-1962).
c# datetime momentjs utc
2
What do you expect? Unix time is the number of seconds since 1970-01-01 00:00:00 UTC. If you need to represent dates befor this, choose another representation.
– Klaus Gütter
Nov 14 '18 at 19:05
I am getting this value 19. October 1962 (23:00:00 GMT+01:00) for the date 20. October 1962. I think, I can represent dates before 1970 with Unix time but maybe I should serialize/deserialize the date in a different way.
– user9923760
Nov 14 '18 at 19:08
So you think the serializer is to blame?
– None of the Above
Nov 14 '18 at 19:19
I am asking if I can use unix time to represent dates before 1970.
– user9923760
Nov 14 '18 at 19:24
2
stackoverflow.com/questions/31708622/…
– Flydog57
Nov 14 '18 at 20:30
add a comment |
I am having the following problem. If I serialize Dates since 01-01-1970 and I deserialize them it works as expected. But for dates before 01-01-1970 the deserialization with momentjs doesn't work.
DateTime dt = new DateTime(2010, 10, 20);
DateTimeOffset dt2 = new DateTimeOffset(dt).ToUniversalTime();
long a = dt2.ToUnixTimeMilliseconds();
Console.WriteLine("value1: " + a); //1287525600000 => moment(1287525600000).toDate() => Wednesday, 20. October 2010 (00:00:00)
DateTime dtfoo = new DateTime(1962, 10, 20);
DateTimeOffset dtfoo2 = new DateTimeOffset(dtfoo).ToUniversalTime();
long afoo = dtfoo2.ToUnixTimeMilliseconds();
Console.WriteLine("value2: " + afoo); // -227239200000 => moment(-227239200000).toDate() => Friday, 19. October 1962 (23:00:00 GMT+01:00)
Console.ReadLine();
I am deserializing the dates just with moment(unixtime).toDate()
. The first date is 20-10-2010. The second date is 19-10-1962 (instead 20-10-1962).
c# datetime momentjs utc
I am having the following problem. If I serialize Dates since 01-01-1970 and I deserialize them it works as expected. But for dates before 01-01-1970 the deserialization with momentjs doesn't work.
DateTime dt = new DateTime(2010, 10, 20);
DateTimeOffset dt2 = new DateTimeOffset(dt).ToUniversalTime();
long a = dt2.ToUnixTimeMilliseconds();
Console.WriteLine("value1: " + a); //1287525600000 => moment(1287525600000).toDate() => Wednesday, 20. October 2010 (00:00:00)
DateTime dtfoo = new DateTime(1962, 10, 20);
DateTimeOffset dtfoo2 = new DateTimeOffset(dtfoo).ToUniversalTime();
long afoo = dtfoo2.ToUnixTimeMilliseconds();
Console.WriteLine("value2: " + afoo); // -227239200000 => moment(-227239200000).toDate() => Friday, 19. October 1962 (23:00:00 GMT+01:00)
Console.ReadLine();
I am deserializing the dates just with moment(unixtime).toDate()
. The first date is 20-10-2010. The second date is 19-10-1962 (instead 20-10-1962).
c# datetime momentjs utc
c# datetime momentjs utc
asked Nov 14 '18 at 19:01
user9923760user9923760
1079
1079
2
What do you expect? Unix time is the number of seconds since 1970-01-01 00:00:00 UTC. If you need to represent dates befor this, choose another representation.
– Klaus Gütter
Nov 14 '18 at 19:05
I am getting this value 19. October 1962 (23:00:00 GMT+01:00) for the date 20. October 1962. I think, I can represent dates before 1970 with Unix time but maybe I should serialize/deserialize the date in a different way.
– user9923760
Nov 14 '18 at 19:08
So you think the serializer is to blame?
– None of the Above
Nov 14 '18 at 19:19
I am asking if I can use unix time to represent dates before 1970.
– user9923760
Nov 14 '18 at 19:24
2
stackoverflow.com/questions/31708622/…
– Flydog57
Nov 14 '18 at 20:30
add a comment |
2
What do you expect? Unix time is the number of seconds since 1970-01-01 00:00:00 UTC. If you need to represent dates befor this, choose another representation.
– Klaus Gütter
Nov 14 '18 at 19:05
I am getting this value 19. October 1962 (23:00:00 GMT+01:00) for the date 20. October 1962. I think, I can represent dates before 1970 with Unix time but maybe I should serialize/deserialize the date in a different way.
– user9923760
Nov 14 '18 at 19:08
So you think the serializer is to blame?
– None of the Above
Nov 14 '18 at 19:19
I am asking if I can use unix time to represent dates before 1970.
– user9923760
Nov 14 '18 at 19:24
2
stackoverflow.com/questions/31708622/…
– Flydog57
Nov 14 '18 at 20:30
2
2
What do you expect? Unix time is the number of seconds since 1970-01-01 00:00:00 UTC. If you need to represent dates befor this, choose another representation.
– Klaus Gütter
Nov 14 '18 at 19:05
What do you expect? Unix time is the number of seconds since 1970-01-01 00:00:00 UTC. If you need to represent dates befor this, choose another representation.
– Klaus Gütter
Nov 14 '18 at 19:05
I am getting this value 19. October 1962 (23:00:00 GMT+01:00) for the date 20. October 1962. I think, I can represent dates before 1970 with Unix time but maybe I should serialize/deserialize the date in a different way.
– user9923760
Nov 14 '18 at 19:08
I am getting this value 19. October 1962 (23:00:00 GMT+01:00) for the date 20. October 1962. I think, I can represent dates before 1970 with Unix time but maybe I should serialize/deserialize the date in a different way.
– user9923760
Nov 14 '18 at 19:08
So you think the serializer is to blame?
– None of the Above
Nov 14 '18 at 19:19
So you think the serializer is to blame?
– None of the Above
Nov 14 '18 at 19:19
I am asking if I can use unix time to represent dates before 1970.
– user9923760
Nov 14 '18 at 19:24
I am asking if I can use unix time to represent dates before 1970.
– user9923760
Nov 14 '18 at 19:24
2
2
stackoverflow.com/questions/31708622/…
– Flydog57
Nov 14 '18 at 20:30
stackoverflow.com/questions/31708622/…
– Flydog57
Nov 14 '18 at 20:30
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
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%2f53307085%2fserialize-deserialize-utc-datetimes-before-01-01-1970%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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%2f53307085%2fserialize-deserialize-utc-datetimes-before-01-01-1970%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
2
What do you expect? Unix time is the number of seconds since 1970-01-01 00:00:00 UTC. If you need to represent dates befor this, choose another representation.
– Klaus Gütter
Nov 14 '18 at 19:05
I am getting this value 19. October 1962 (23:00:00 GMT+01:00) for the date 20. October 1962. I think, I can represent dates before 1970 with Unix time but maybe I should serialize/deserialize the date in a different way.
– user9923760
Nov 14 '18 at 19:08
So you think the serializer is to blame?
– None of the Above
Nov 14 '18 at 19:19
I am asking if I can use unix time to represent dates before 1970.
– user9923760
Nov 14 '18 at 19:24
2
stackoverflow.com/questions/31708622/…
– Flydog57
Nov 14 '18 at 20:30