Date Methods (Date.now(),Date toISOString() and Date toJSON() Methods)
- Date.naw() method used to return the number of milliseconds elapsed since January 1, 1970, 00:00:00 UTC.
- Date toISOString() converts a date to an ISO 8601 format string (e.g., “YYYY-MM-DDTHH:mm:ss.sssZ”).
- Date toJSON() method converts the given date object’s contents into a string.
Syntax:
let A = Date.now(); // Date.now()
dateObj.toISOString() // Date toISOString()
dateObj.toJSON() // Date toJSON()
Example: In this example we are using the abobe-explained methods.
Javascript
// Using new Date let currentDate = new Date(); // Using Date.now() let timestamp = Date.now(); console.log( "Timestamp:" , timestamp); // Using Date.toISOString() let isoString = currentDate.toISOString(); console.log( "ISO String:" , isoString); // Using Date.toJSON() let jsonDate = currentDate.toJSON(); console.log( "JSON Date:" , jsonDate); |
Timestamp: 1698213643835 ISO String: 2023-10-25T06:00:43.835Z JSON Date: 2023-10-25T06:00:43.835Z
JavaScript ES5 (JS 2009)
JavaScript 2009 (ES5) refers to the fifth edition of the ECMAScript language specification, standardized in 2009. It introduced several features, like strict mode, new methods, JSON support, and improved syntax for better programming practices and compatibility across browsers.
ECMAScript 5 (ES5) introduced several significant features to JavaScript, enhancing the language’s capabilities.
Name |
Description |
---|---|
Enforces stricter parsing and error handling in JavaScript code. |
|
Removes whitespace from the beginning and end. |
|
Use backslashes at the end of each line to continue. |
|
Check if an object is an array. |
|
Iterates over array elements, applying a provided function. |
|
Transforms each array element using a provided function. |
|
Creates a new array with elements passing a test. |
|
Combines an array of elements to produce a single result. |
|
Combines array elements from right to left. |
|
Checks if all elements satisfy a given condition. |
|
Checks if any element satisfies a given condition. |
|
Returns the index of a specified element. |
|
Returns the last index of a specified element. |
|
Converts JSON string to JavaScript object. |
|
Converts JavaScript object to JSON formatted string. |
|
Returns the current timestamp in milliseconds since 1970. |
|
Converts date to ISO 8601 format string. |
|
Converts date to JSON-formatted string (ISO 8601). |
|
Property Getters and Setters |
Control object property access and modification behavior. |
Defines or modifies a property’s attributes on an object. |
|
Defines or modifies multiple properties’ attributes on an object. |
|
Gets attributes of a property from an object. |
|
Returns an array of enumerable property names in object. |
|
Returns an array of all property names in object. |
|
Prevents adding new properties to an object. |
|
Checks if new properties can be added. |
|
Prevents new properties and makes existing non-configurable. |
|
Checks if object properties are non-configurable and sealed. |
|
Prevents adding, modifying, and makes properties non-writable. |
|
Checks if object properties are non-writable, non-configurable, and frozen. |
Here is the explanation of above-mentioned topic
Contact Us