Get the beginning of the day in timestamp using Momentjs library
For instance the timestamp is: 1542769200 which its output is: GMT: Wednesday, 21 November 2018 03:00:00.
However what I am trying to achieve is to get the beginning of this day, by having the hour, minutes and seconds set to 00.00.00.
javascript momentjs
add a comment |
For instance the timestamp is: 1542769200 which its output is: GMT: Wednesday, 21 November 2018 03:00:00.
However what I am trying to achieve is to get the beginning of this day, by having the hour, minutes and seconds set to 00.00.00.
javascript momentjs
add a comment |
For instance the timestamp is: 1542769200 which its output is: GMT: Wednesday, 21 November 2018 03:00:00.
However what I am trying to achieve is to get the beginning of this day, by having the hour, minutes and seconds set to 00.00.00.
javascript momentjs
For instance the timestamp is: 1542769200 which its output is: GMT: Wednesday, 21 November 2018 03:00:00.
However what I am trying to achieve is to get the beginning of this day, by having the hour, minutes and seconds set to 00.00.00.
javascript momentjs
javascript momentjs
asked Nov 12 '18 at 17:55
Heyab ReddaHeyab Redda
199317
199317
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
moment(moment(moment().unix() * 1000).startOf('day').unix() * 1000)
I have val = 1542769200; How and where do I use this variable in the expression that you have provided?
– Heyab Redda
Nov 12 '18 at 18:12
moment(moment(val).startOf('day').unix() * 1000)
– knighteq
Nov 12 '18 at 18:14
Remember that timestamp is in seconds, but in javascript we operate in miliseconds, so you should multiply your timestamp by 1000. When you have your moment date then you check the start of the day, and you can convert it to timestamp by the '.unix()' method..
– knighteq
Nov 12 '18 at 18:16
This does not really give me what I am trying to achieve. Take this is mind as timestamp: 1542769200, according to your expression this does not return me the beginning of its day
– Heyab Redda
Nov 12 '18 at 18:19
jsfiddle.net/1tmzfu8q - is this what you need?
– knighteq
Nov 12 '18 at 18:28
add a comment |
You could do something like this:
var timestamp = 1542769200;
var date = moment.unix(timestamp).startOf('day')
console.log('date:', moment.unix(timestamp).format())
console.log('start of day:', date.format())
console.log('new unix:', date.unix())
console.log('test:', moment.unix(date.unix()).format())
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment.min.js"></script>
Thank you! @Akrion
– Heyab Redda
Nov 12 '18 at 20:23
add a comment |
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%2f53267599%2fget-the-beginning-of-the-day-in-timestamp-using-momentjs-library%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
moment(moment(moment().unix() * 1000).startOf('day').unix() * 1000)
I have val = 1542769200; How and where do I use this variable in the expression that you have provided?
– Heyab Redda
Nov 12 '18 at 18:12
moment(moment(val).startOf('day').unix() * 1000)
– knighteq
Nov 12 '18 at 18:14
Remember that timestamp is in seconds, but in javascript we operate in miliseconds, so you should multiply your timestamp by 1000. When you have your moment date then you check the start of the day, and you can convert it to timestamp by the '.unix()' method..
– knighteq
Nov 12 '18 at 18:16
This does not really give me what I am trying to achieve. Take this is mind as timestamp: 1542769200, according to your expression this does not return me the beginning of its day
– Heyab Redda
Nov 12 '18 at 18:19
jsfiddle.net/1tmzfu8q - is this what you need?
– knighteq
Nov 12 '18 at 18:28
add a comment |
moment(moment(moment().unix() * 1000).startOf('day').unix() * 1000)
I have val = 1542769200; How and where do I use this variable in the expression that you have provided?
– Heyab Redda
Nov 12 '18 at 18:12
moment(moment(val).startOf('day').unix() * 1000)
– knighteq
Nov 12 '18 at 18:14
Remember that timestamp is in seconds, but in javascript we operate in miliseconds, so you should multiply your timestamp by 1000. When you have your moment date then you check the start of the day, and you can convert it to timestamp by the '.unix()' method..
– knighteq
Nov 12 '18 at 18:16
This does not really give me what I am trying to achieve. Take this is mind as timestamp: 1542769200, according to your expression this does not return me the beginning of its day
– Heyab Redda
Nov 12 '18 at 18:19
jsfiddle.net/1tmzfu8q - is this what you need?
– knighteq
Nov 12 '18 at 18:28
add a comment |
moment(moment(moment().unix() * 1000).startOf('day').unix() * 1000)
moment(moment(moment().unix() * 1000).startOf('day').unix() * 1000)
answered Nov 12 '18 at 18:08
knighteqknighteq
662
662
I have val = 1542769200; How and where do I use this variable in the expression that you have provided?
– Heyab Redda
Nov 12 '18 at 18:12
moment(moment(val).startOf('day').unix() * 1000)
– knighteq
Nov 12 '18 at 18:14
Remember that timestamp is in seconds, but in javascript we operate in miliseconds, so you should multiply your timestamp by 1000. When you have your moment date then you check the start of the day, and you can convert it to timestamp by the '.unix()' method..
– knighteq
Nov 12 '18 at 18:16
This does not really give me what I am trying to achieve. Take this is mind as timestamp: 1542769200, according to your expression this does not return me the beginning of its day
– Heyab Redda
Nov 12 '18 at 18:19
jsfiddle.net/1tmzfu8q - is this what you need?
– knighteq
Nov 12 '18 at 18:28
add a comment |
I have val = 1542769200; How and where do I use this variable in the expression that you have provided?
– Heyab Redda
Nov 12 '18 at 18:12
moment(moment(val).startOf('day').unix() * 1000)
– knighteq
Nov 12 '18 at 18:14
Remember that timestamp is in seconds, but in javascript we operate in miliseconds, so you should multiply your timestamp by 1000. When you have your moment date then you check the start of the day, and you can convert it to timestamp by the '.unix()' method..
– knighteq
Nov 12 '18 at 18:16
This does not really give me what I am trying to achieve. Take this is mind as timestamp: 1542769200, according to your expression this does not return me the beginning of its day
– Heyab Redda
Nov 12 '18 at 18:19
jsfiddle.net/1tmzfu8q - is this what you need?
– knighteq
Nov 12 '18 at 18:28
I have val = 1542769200; How and where do I use this variable in the expression that you have provided?
– Heyab Redda
Nov 12 '18 at 18:12
I have val = 1542769200; How and where do I use this variable in the expression that you have provided?
– Heyab Redda
Nov 12 '18 at 18:12
moment(moment(val).startOf('day').unix() * 1000)
– knighteq
Nov 12 '18 at 18:14
moment(moment(val).startOf('day').unix() * 1000)
– knighteq
Nov 12 '18 at 18:14
Remember that timestamp is in seconds, but in javascript we operate in miliseconds, so you should multiply your timestamp by 1000. When you have your moment date then you check the start of the day, and you can convert it to timestamp by the '.unix()' method..
– knighteq
Nov 12 '18 at 18:16
Remember that timestamp is in seconds, but in javascript we operate in miliseconds, so you should multiply your timestamp by 1000. When you have your moment date then you check the start of the day, and you can convert it to timestamp by the '.unix()' method..
– knighteq
Nov 12 '18 at 18:16
This does not really give me what I am trying to achieve. Take this is mind as timestamp: 1542769200, according to your expression this does not return me the beginning of its day
– Heyab Redda
Nov 12 '18 at 18:19
This does not really give me what I am trying to achieve. Take this is mind as timestamp: 1542769200, according to your expression this does not return me the beginning of its day
– Heyab Redda
Nov 12 '18 at 18:19
jsfiddle.net/1tmzfu8q - is this what you need?
– knighteq
Nov 12 '18 at 18:28
jsfiddle.net/1tmzfu8q - is this what you need?
– knighteq
Nov 12 '18 at 18:28
add a comment |
You could do something like this:
var timestamp = 1542769200;
var date = moment.unix(timestamp).startOf('day')
console.log('date:', moment.unix(timestamp).format())
console.log('start of day:', date.format())
console.log('new unix:', date.unix())
console.log('test:', moment.unix(date.unix()).format())
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment.min.js"></script>
Thank you! @Akrion
– Heyab Redda
Nov 12 '18 at 20:23
add a comment |
You could do something like this:
var timestamp = 1542769200;
var date = moment.unix(timestamp).startOf('day')
console.log('date:', moment.unix(timestamp).format())
console.log('start of day:', date.format())
console.log('new unix:', date.unix())
console.log('test:', moment.unix(date.unix()).format())
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment.min.js"></script>
Thank you! @Akrion
– Heyab Redda
Nov 12 '18 at 20:23
add a comment |
You could do something like this:
var timestamp = 1542769200;
var date = moment.unix(timestamp).startOf('day')
console.log('date:', moment.unix(timestamp).format())
console.log('start of day:', date.format())
console.log('new unix:', date.unix())
console.log('test:', moment.unix(date.unix()).format())
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment.min.js"></script>
You could do something like this:
var timestamp = 1542769200;
var date = moment.unix(timestamp).startOf('day')
console.log('date:', moment.unix(timestamp).format())
console.log('start of day:', date.format())
console.log('new unix:', date.unix())
console.log('test:', moment.unix(date.unix()).format())
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment.min.js"></script>
var timestamp = 1542769200;
var date = moment.unix(timestamp).startOf('day')
console.log('date:', moment.unix(timestamp).format())
console.log('start of day:', date.format())
console.log('new unix:', date.unix())
console.log('test:', moment.unix(date.unix()).format())
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment.min.js"></script>
var timestamp = 1542769200;
var date = moment.unix(timestamp).startOf('day')
console.log('date:', moment.unix(timestamp).format())
console.log('start of day:', date.format())
console.log('new unix:', date.unix())
console.log('test:', moment.unix(date.unix()).format())
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment.min.js"></script>
answered Nov 12 '18 at 19:17
AkrionAkrion
9,40211224
9,40211224
Thank you! @Akrion
– Heyab Redda
Nov 12 '18 at 20:23
add a comment |
Thank you! @Akrion
– Heyab Redda
Nov 12 '18 at 20:23
Thank you! @Akrion
– Heyab Redda
Nov 12 '18 at 20:23
Thank you! @Akrion
– Heyab Redda
Nov 12 '18 at 20:23
add a comment |
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%2f53267599%2fget-the-beginning-of-the-day-in-timestamp-using-momentjs-library%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