Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

date methods js

new Date().toISOString()
'2022-10-11T16:22:51.161Z'
new Date().toJSON()
'2022-10-11T16:22:51.161Z'

new Date().toDateString()
'Tue Oct 11 2022'
new Date().toGMTString()
'Tue, 11 Oct 2022 16:22:51 GMT'
new Date().toUTCString()
'Tue, 11 Oct 2022 16:22:51 GMT'

new Date().toTimeString()
'21:52:51 GMT+0530 (India Standard Time)'
new Date().toString()
'Tue Oct 11 2022 21:52:51 GMT+0530 (India Standard Time)'

new Date().toLocaleDateString()
'11/10/2022'
new Date().toLocaleTimeString()
'21:52:51'
new Date().toLocaleString()
'11/10/2022, 21:52:51'
Comment

javascript date methods

Date(): Returns today's date and time
getDate(): Returns the day of the month for the specified date according to the local time
getDay(): Returns the day of the week for the specified date according to the local time
getFullYear(): Returns the year of the specified date according to the local time
getHours(): Returns the hour in the specified date according to the local time
getMilliseconds(): Returns the milliseconds in the specified date according to the local time
getMinutes(): Returns the minutes in the specified date according to the local time
getMonth(): Returns the month in the specified date according to the local time
getSeconds(): Returns the seconds in the specified date according to the local time
getTime(): Returns the numeric value of the specified date as the number of milliseconds since January 1, 1970, 00:00:00 UTC
getTimezoneOffset(): Returns the time-zone offset in minutes for the current locale
getUTCDate(): Returns the day (date) of the month in the specified date according to the universal time
getUTCDay(): Returns the day of the week in the specified date according to the universal time
getUTCFullYear(): Returns the year in the specified date according to the universal time
getUTCHours(): Returns the hours in the specified date according to the universal time
getUTCMilliseconds(): Returns the milliseconds in the specified date according to the universal time
getUTCMinutes(): Returns the minutes in the specified date according to the universal time
getUTCMonth(): Returns the month in the specified date according to the universal time
getUTCSeconds(): Returns the seconds in the specified date according to the universal time
setDate(): Sets the day of the month for a specified date according to the local time
setFullYear(): Sets the full year for a specified date according to the local time
setHours(): Sets the hours for a specified date according to the local timesetMilliseconds()
Comment

JavaScript Date Methods

JavaScript Date Methods
There are various methods available in JavaScript Date object.

Method	Description
now()	Returns the numeric value corresponding to the current time (the number of milliseconds elapsed since January 1, 1970 00:00:00 UTC)
getFullYear()	Gets the year according to local time
getMonth()	Gets the month, from 0 to 11 according to local time
getDate()	Gets the day of the month (1–31) according to local time
getDay()	Gets the day of the week (0-6) according to local time
getHours()	Gets the hour from 0 to 23 according to local time
getMinutes	Gets the minute from 0 to 59 according to local time
getUTCDate()	Gets the day of the month (1–31) according to universal time
setFullYear()	Sets the full year according to local time
setMonth()	Sets the month according to local time
setDate()	Sets the day of the month according to local time
setUTCDate()	Sets the day of the month according to universal time
Comment

Date Methods javascript

const timeInMilliseconds = Date.now();
console.log(timeInMilliseconds); // 1593765214488
const time = new Date;
// get day of the month
const date = time.getDate();
console.log(date); // 30
// get day of the week
const year = time.getFullYear();
console.log(year); // 2020
const utcDate = time.getUTCDate();
console.log(utcDate); // 30
const event = new Date('Feb 19, 2020 23:15:30');
// set the date
event.setDate(15);
console.log(event.getDate()); // 15
// Only 28 days in February!
event.setDate(35);

console.log(event.getDate()); // 7
Comment

define datemethod in javascript

// EXAMPLE :
        
        // Print today full date & full time:
let now = new Date();
        let today = [
            "Date:" + now.getDate(),
            "Month: " + (now.getMonth()+1),
            "Year: " + now.getFullYear(),
            "Day: " + now.getDay(),
            "Hours: " + now.getHours(), "Minutes: " + now.getMinutes(),
            "Seconds: " + now.getSeconds(),
            "Milisecondss: " + now.getMilliseconds()]

        let today_data =today.forEach((ele => document.write (ele + "<br>")));
    
    document.write(today_data());
// OUTPUT:
        // Date: 12
        // Month: 10
        // Year: 2022
        // Day: 3
        // Hours: 23
        // Minutes: 31
        // Seconds: 12
        // Milisecondss: 178
Comment

define datemethod in javascript

// EXAMPLE : 

        // Print today full date & full time:
        let today = [
            "Date:" + now.getDate(),
            "Month: " + (now.getMonth() + 1),
            "Year: " + now.getFullYear(),
            "Day: " + now.getDay(),
            "Hours: " + now.getHours(), "Minutes: " + now.getMinutes(),
            "Seconds: " + now.getSeconds(),
            "Milisecondss: " + now.getMilliseconds()]

        let today_data = today.forEach((ele => document.write(ele + "<br>")));

        document.write(today_data());
        // OUTPUT:
        // Date: 12
        // Month: 10
        // Year: 2022
        // Day: 3
        // Hours: 23
        // Minutes: 31
        // Seconds: 12
        // Milisecondss: 178
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript this Inside Inner Function 
Javascript :: javascript Duplicating a parameter name is not allowed 
Javascript :: javascript Working of multiple yield Statements 
Javascript :: django debug toolbar javascript error 
Javascript :: JavaScript Object Prototypes 
Javascript :: js console.log callstack 
Javascript :: find the missing number in js 
Javascript :: node js - excecute a child process and exchange message to and from 
Javascript :: nodejs: Basic: managing file: Read, Write, Create, Delete 
Javascript :: circular object array 
Javascript :: jQuery Prevent Submit on Enter Key Except in Textarea 
Javascript :: use anchor element to open file 
Javascript :: change y scale phaser 
Javascript :: phaser place on rectangle shift 
Javascript :: phaser enable pixel art 
Javascript :: How to call the API when the search value changes 
Javascript :: core.mjs:4057 JIT compilation failed for NgModule class AppModule 
Javascript :: js undici fetch stream data 
Javascript :: javascript concat two htmlcollection 
Javascript :: javascript list all elements in set 
Javascript :: Slice and Splice -Javascript 2 
Javascript :: change text color according to background js 
Javascript :: export default function react 
Javascript :: kafkajs 
Javascript :: vue sidebar 
Javascript :: nodejs 
Javascript :: export default class react 
Javascript :: how to read excel file in nodejs 
Javascript :: how to check empty string array in javascript 
Javascript :: scroll position 
ADD CONTENT
Topic
Content
Source link
Name
8+6 =