WebMasterCampus
WEB DEVELOPER Resources

Javascript How to Get the Current Date

Learn How to Get the Current Date in Javascript


Get the Current Date in Javascript

We can use Date() function to generate a new Date object that will have a current date and time.

Example 1


    let d1 = new Date();  //Current Date
    //let d1 = new Date("2011-10-14T03:24:00");  //Past Date

    let options = {weekday:"long", day:"numeric", month:"numeric", year:"numeric"}

    console.log(d1.toLocaleDateString("en-us", options));
    console.log(d1.toLocaleDateString("en-gb", options));

Example 2


    let d1 = new Date(); //Current Date
     //let d1 = new Date("2011-10-14T03:24:00");  //Past Date

    let day = String(d1.getDate()).padStart(2, '0');
    let month = String(d1.getMonth()).padStart(2, '0');
    let year = d1.getFullYear();

    let date_GB = day + "-" + month + "-" + year;
    let date_US = month + "-" + day + "-" + year;

    console.log(date_GB);
    console.log(date_US);

It’s very handy to change sequence of currentDate = month + ‘/’ + day + ‘/’ + year; to whatever format you wish.

Like for British format you can use currentDate = day + ‘/’ + month + ‘/’ + year;

Learn more about toLocaleDateString()

Learn more about DateTimeFormat()

Learn more about Date

Common Locales

  • ar-SA: For Arabic (Saudi Arabia)
  • bn-BD: For Bangla (Bangladesh)
  • bn-IN: For Bangla (India)
  • cs-CZ: For Czech (Czech Republic)
  • da-DK: For Danish (Denmark)
  • de-AT: For Austrian German
  • de-CH: For “Swiss” German
  • de-DE: For Standard German (as spoken in Germany)
  • el-GR: For Modern Greek
  • en-AU: For Australian English
  • en-CA: For Canadian English
  • en-GB: For British English
  • en-IE: For Irish English
  • en-IN: For Indian English
  • en-NZ: For New Zealand English
  • en-US: For US English
  • en-ZA: For English (South Africa)
  • es-AR: For Argentine Spanish
  • es-CL: For Chilean Spanish
  • es-CO: For Colombian Spanish
  • es-ES: For Castilian Spanish (as spoken in Central-Northern Spain)
  • es-MX: For Mexican Spanish
  • es-US: For American Spanish
  • fi-FI: For Finnish (Finland)
  • fr-BE: For Belgian French
  • fr-CA: For Canadian French
  • fr-CH: For “Swiss” French
  • fr-FR: For Standard French (especially in France)
  • he-IL: For Hebrew (Israel)
  • hi-IN: For Hindi (India)
  • hu-HU: For Hungarian (Hungary)
  • id-ID: For Indonesian (Indonesia)
  • it-CH: For “Swiss” Italian
  • it-IT: For Standard Italian (as spoken in Italy)
  • jp-JP: For Japanese (Japan)
  • ko-KR: For Korean (Republic of Korea)
  • nl-BE: For Belgian Dutch
  • nl-NL: For Standard Dutch (as spoken in The Netherlands)
  • no-NO: For Norwegian (Norway)
  • pl-PL: For Polish (Poland)
  • pt-BR: For Brazilian Portuguese
  • pt-PT: For European Portuguese (as written and spoken in Portugal)
  • ro-RO: For Romanian (Romania)
  • ru-RU: For Russian (Russian Federation)
  • sk-SK: For Slovak (Slovakia)
  • sv-SE: For Swedish (Sweden)
  • ta-IN: For Indian Tamil
  • ta-LK: For Sri Lankan Tamil
  • th-TH: For Thai (Thailand)
  • tr-TR: For Turkish (Turkey)
  • zh-CN: For Mainland China, simplified characters
  • zh-HK: For Hong Kong, traditional characters
  • zh-TW: For Taiwan, traditional characters
Created with love and passion.