Skip to content

Instantly share code, notes, and snippets.

@autioch
Created May 20, 2017 08:44
Show Gist options
  • Save autioch/8f7499126608e09714db7e1c95e379f5 to your computer and use it in GitHub Desktop.
Save autioch/8f7499126608e09714db7e1c95e379f5 to your computer and use it in GitHub Desktop.
Date methods
/* eslint no-inline-comments: 0 */
/* eslint line-comment-position: 0 */
/* eslint no-unused-expressions: 0 */
// Object.getOwnPropertyNames(Date);
Date.length; // 7 - number
Date.name; // Date - string
Date.arguments; // null - object
Date.caller; // null - object
Date.prototype; // prototype - could not call this.
Date.now(); // 1495269792944
Date.parse(); // NaN
Date.UTC(); // NaN
// Object.getOwnPropertyNames(Date.prototype);
new Date().constructor(); // Sat May 20 2017 10:43:12 GMT+0200 (Środkowoeuropejski czas letni)
new Date().toString(); // Sat May 20 2017 10:43:12 GMT+0200 (Środkowoeuropejski czas letni)
new Date().toDateString(); // Sat May 20 2017
new Date().toTimeString(); // 10:43:12 GMT+0200 (Środkowoeuropejski czas letni)
new Date().toISOString(); // 2017-05-20T08:43:12.944Z
new Date().toUTCString(); // Sat, 20 May 2017 08:43:12 GMT
new Date().toGMTString(); // Sat, 20 May 2017 08:43:12 GMT
new Date().getDate(); // 20
new Date().setDate(); // NaN
new Date().getDay(); // 6
new Date().getFullYear(); // 2017
new Date().setFullYear(); // NaN
new Date().getHours(); // 10
new Date().setHours(); // NaN
new Date().getMilliseconds(); // 945
new Date().setMilliseconds(); // NaN
new Date().getMinutes(); // 43
new Date().setMinutes(); // NaN
new Date().getMonth(); // 4
new Date().setMonth(); // NaN
new Date().getSeconds(); // 12
new Date().setSeconds(); // NaN
new Date().getTime(); // 1495269792945
new Date().setTime(); // NaN
new Date().getTimezoneOffset(); // -120
new Date().getUTCDate(); // 20
new Date().setUTCDate(); // NaN
new Date().getUTCDay(); // 6
new Date().getUTCFullYear(); // 2017
new Date().setUTCFullYear(); // NaN
new Date().getUTCHours(); // 8
new Date().setUTCHours(); // NaN
new Date().getUTCMilliseconds(); // 945
new Date().setUTCMilliseconds(); // NaN
new Date().getUTCMinutes(); // 43
new Date().setUTCMinutes(); // NaN
new Date().getUTCMonth(); // 4
new Date().setUTCMonth(); // NaN
new Date().getUTCSeconds(); // 12
new Date().setUTCSeconds(); // NaN
new Date().valueOf(); // 1495269792946
new Date().getYear(); // 117
new Date().setYear(); // NaN
new Date().toJSON(); // 2017-05-20T08:43:12.946Z
new Date().toLocaleString(); // 2017-05-20 10:43:12
new Date().toLocaleDateString(); // 2017-05-20
new Date().toLocaleTimeString(); // 10:43:12
// /* SCRIPT TO GENERATE THE DATE OUTPUT. */
//
// /* eslint no-console: 0 */
// const lines = [
// '/* eslint no-inline-comments: 0 */',
// '/* eslint line-comment-position: 0 */',
// '/* eslint no-unused-expressions: 0 */',
// '\r\n// Object.getOwnPropertyNames(Date);\r\n'
// ];
//
// const datePropertyNames = Object.getOwnPropertyNames(Date);
//
// datePropertyNames.forEach((propName) => {
// if (typeof Date[propName] === 'function') {
// lines.push(`Date.${propName}(); // ${Date[propName]()}`);
// } else {
// try {
// lines.push(`Date.${propName}; // ${Date[propName]} - ${typeof Date[propName]}`);
// } catch (err) {
// lines.push(`Date.${propName}; // ${propName} - could not call this.`);
// }
// }
// });
//
// lines.push('\r\n// Object.getOwnPropertyNames(Date.prototype);\r\n');
//
// const datePrototypePropertyNames = Object.getOwnPropertyNames(Date.prototype);
//
// datePrototypePropertyNames.forEach((propName) => {
// if (typeof Date.prototype[propName] === 'function') {
// lines.push(`new Date().${propName}(); // ${new Date()[propName]()}`);
// } else {
// lines.push(`new Date().${propName}; // ${Date.prototype[propName]} - ${typeof Date.prototype[propName]}`);
// }
// });
//
// const theCode = require('fs').readFile(__filename, 'utf-8', (err, scriptLines) => {
// if (err) {
// console.log(err.message);
// }
//
// const resultLines = lines.concat('\r\n').join('\r\n');
// const commentedScriptLines = scriptLines
// .split('\n')
// .map((line) => `// ${line}`)
// .concat('\n')
// .join('\n');
//
// require('fs').writeFile('dateTypes.js', resultLines + commentedScriptLines, 'utf-8', () => console.log('done'));
// });
//
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment