Skip to content
Advertisements

JavaScript Date.setTime()

Why setTime ?

Javascript Date setTime() method sets the Date object to the time represented by a number of milliseconds since January 1, 1970, 00:00:00 UTC.

Syntax:

Date.setTime(millisec)

  • millisec (required): The number of milliseconds to be added to, or subtracted from, midnight January 1, 1970

Return:

  • The number of milliseconds between 1 January 1970 00:00:00 UTC and the updated date.

JavaScript setTime Examples

Example 1

        var date = new Date('October 22, 2019 15:22:17:432');
        date.setTime(2500000000);
        console.log( date );

Fri Jan 30 1970 01:26:40 GMT+0300


Example 2

        var date1 = new Date('July 31, 2019');
        var date2 = new Date();

        date2.setTime(date1.getTime());

        console.log(date1);

        console.log(date2);

Wed Jul 31 2019 00:00:00 GMT+0300
Wed Jul 31 2019 00:00:00 GMT+0300


Browser Support

Chromeyes
Edgeyes
Firefox1
Internet Exploreryes
Operayes
Safariyes
Android webviewyes
Chrome for Androidyes
Edge mobileyes
Firefox for Android4
Opera Androidyes
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: