[Javascript] someJavascript (Date)

  1. Include Scripts
  2. #script src="myscript.js"##/script# >>> Before closing body tag

  3. Basic Date
    const myDate = new Date()
  4. myDate.getFullYear()
  5. myDate.getMonth() Careful, it's 0 based (0-11)
  6. myDate.getDate() #This one ok (1-31)
  7. myDate.getDay() 0 based (0-6) >>> Sun to Sat

  8. Good example
                  
                    const myDayList = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
                    const myMonthList = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];
              
                    const myDate = new Date();
              
                    let myYear = myDate.getFullYear();
                    let myRawMonth = myDate.getMonth();
                    let myDayNumber = myDate.getDate();
                    let myRawDayName = myDate.getDay();
              
                    let myMonth = myMonthList[myRawMonth];
                    let myDayName = myDayList[myRawDayName];
              
                    myDateArray = [myYear, myMonth, myDayNumber, myDayName];
                    myDateString = myDateArray.join(" ");
                    alert(myDateString);
                  
                
  9. Set Date

  10.       const myDate = new Date(2023, 1, 2);
          // Beware the month is of 0 based
          alert(myDate);
    
          myDate.setFullYear(1992);
          myDate.setMonth(5);
          myDate.setDate(19);
    
          alert(myDate.toString());
          alert(myDate.toUTCString());
          alert(myDate.toLocaleString());
          alert(myDate.toDateString());
          alert(myDate.toTimeString());
                

Source: ---


Disclaimer: The information in this webpage is shared by anonymous users from external online sources. We cannot guarantee its accuracy or truthfulness. Users should exercise caution and verify information independently.


© 2023 maginokarp.com