Get your current local date and time with .now()

.now()


Description: Get the current local date and time.


Example:

<!doctype html>
    <html lang="en">
    <head>
      <meta charset="utf-8">
      <title>now demo</title>
      <script src="http://code.bitsycode.com/bitsycode-latest.min.js"></script>
    </head>
    <body>
      
      <span class="date"></span><br />
      <span class="time"></span>
      
      <script>
         
        bitsyCode.ready(function(){
            
            bitsyCode(".date").html(bitsyCode.now({ format:"%D, %d %MM %Y" }));
            
            setInterval(function(){
               bitsyCode(".time").html(bitsyCode.now({ format:"%H : %m : %s %p" }));
            }, 1000);
            
        })
         
      </script>
     
    </body>
    </html>

Preview:


  • Usage

    • How to use:

      Get your current local date and time, with formatting options

    • Simple Usage:

      bitsyCode.now() //Using default settings
    • Custom Formatting:

      bitsyCode.now({ format: '%d/%M/%Y %H:%m:%s' }) // day/month/year hours:minutes:seconds
    • With 12-hour time:

      bitsyCode.now({ format: '%d/%M/%Y %H:%m:%s', _12hour:true }) // hours:minutes:seconds (12-hour time format)
  • Options

    • Date formatting (List below)

      format: '%d-%M-%Y %H:%m:%s' (default value), view the complete format list below.


      Get UTC Full Year

      '%Y' // get UTC Full Year

      Get Month in numeric value

      '%M' // get month in numeric value

      Get Month in string value

      '%MM' // get month name in string

      Get Day in numeric value

      '%d' // get numeric Day

      Get Day in string value

      '%D' // get numeric Day

      Get time Hours

      '%H' // get Hours

      Get time Minutes

      '%m' // get Minutes

      Get time Seconds

      '%s' // get Seconds

      Get time period, (AM or PM)

      '%p' // get Period either am or pm

    • Setting 12-hour time format
      _12hour: false (default value) // Set this to true if you want a 12-hour time format
  • Returns

    • Returns: Current formatted local date.
Share