-4

I have some date in milliseconds as 1425133515000 . Now in javascript I need to verify whether 1425133515000 is today or not. Is it possible?

I need one method which takes date in milli seconds and return true if date in milliseconds is today.

user755806
  • 6,565
  • 27
  • 106
  • 153
  • 1
    You should try a bit by yourself and look around before asking questions. – Telokis Feb 28 '15 at 16:51
  • I am new to Javascript. Could u plz help me? – user755806 Feb 28 '15 at 16:52
  • If you are in need of date manipulation there is a very good library for doing exactly that: http://momentjs.com/ – tgo Feb 28 '15 at 16:53
  • It looks like you're using a Unix Timestamp which is actually in seconds, and not in milliseconds. Check out the `Moment.js` project for this kind of operation. Here's a documentation link: http://momentjs.com/docs/#/parsing/unix-timestamp/ – Zane Helton Feb 28 '15 at 16:53

2 Answers2

3

New date object from miliseconds:

var dateFromMs = new Date(1425133515000);

And comparsion based on How to know date is today?:

var today = new Date();
if (today.toDateString() === dateFromMs.toDateString()) {
    alert('today');
}
Community
  • 1
  • 1
Kepi
  • 374
  • 2
  • 7
1

You could use the Date constructor taking an Integer value representing the number of milliseconds since 1 January 1970 00:00:00 UTC (Unix Epoch) - which is what your integer value represents:

vat date = new Date(1425133515000);
var now = new Date();

Now all that's left is compare is whether the 2 dates represent the same calendar day:

var isSameDay = 
    date.getDate() === now.getDate() && 
    date.getMonth() === now.getMonth() &&
    date.getFullYear() === now.getFullYear();
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928