Time and Dates

Video

JavaScript Notes

JavaScript
    // Date objects in JavaScript
    let log = console.log( );
    let d = new Date( );   // holds current time and date from computer. Note, ‘new’ creates a new Object!
    let num = 1000 * 60 * 60 * 24 * 365.25 * 40;
    // approx. 40 years

    // ms * sec * min * hr * day * year * x
    let str = '20 July 2012 14:05:00';
    let d1 = new Date(15000000);

    // count number of milliseconds passed since the Unix Epoch Jan 1 00:00:00.000 1970
    let d2 = new Date(num);  //should return Jan 1, 2010
    let d3 = new Date(str);
    let d4 = new Date(2017, 0-11, 1, 12, 30, 0, 123);  // months go from 0 to 11
    let d3
    d.setFullYear(2020);   // changes the year of the date object
    d.setHours( ); // setMinutes( ), set Month( )
    let min = d.getMinutes( );
    let day = d.getDay( );
    log (min, day);
    
    //OUTPUT
    /***
    d.toDateString( )  // date portion UTC time
    d.toTimeString( )  // time portion UTC time
    d.toISOString( )  // date simplified UTC
    d.toJSON   // date for use in JSON string UTC
    
    d.toLocaleString( )  // local time and date
    d.toLocaleString('en-CA' )  // local time and date with specified formatting
    d.toUTCString( )
    **/