javascript : Date.format(strFormat)

 

javascript : Date.format(strFormat)


Target:

Applicable with Date Data Type.


Description :

format Date to string with given format string.

  • strFormat Description
    • dddd : full week day name as ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
    • ddd : three letter week day name as ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]
    • dd : two digit date of month prefix with zero.
    • : date of month without prefix with zero.
    • MMMM : full month name as ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"].
    • MMM : three letter month name as ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"].
    • MM : two digit month number prefix with zero.
    • : month number without prefix with zero.
    • yyyy : full year number in 4 digits.
    • yy : full year number's last 2 digits.
    • HH :Hour in 24 hour format prefix with zero.
    • :Hour in 24 hour format without prefix with zero.
    • hh :Hour in 12 hour format prefix with zero.
    • :Hour in 12 hour format without prefix with zero.
    • mm :Minutes prefix with zero.
    • :Minutes without prefix with zero.
    • ss :Seconds prefix with zero.
    • :Seconds without prefix with zero.
    • fff :Miliseconds in three digits prefix with zero.
    • tt :AM/PM in capital Letter.
    • :am/pm in small letter


Note: strFormat not given then it return Date.toString().



Syntax:

Date.format(strFormat)


Usase:

  1. new Date().format("dd/MMM/yyyy")
    It return string "02/Nov/2019"
  2. new Date().format("dddd dd,MMMM,yyyy")
    It return string "Saturday 02,November,2019"
  3. new Date().format("dddd dd,MMMM,yyyy HH:mm:ss tt")
    It return string "Saturday 02,November,2019 00:03:12 AM"
  4. new Date().format("HH-mm-ss-ff")
    It return string "00-04-51-976"
  5. new Date().format("hh:mm:ss:ff t")
    It return string "00:05:49:739 am"



Download MYJS.js

MyJs is a collection of java script extension methods that enhances the JavaScript objects, class object, DOM element, domElementsCollections, Date, String, Number and other data type. 

Include in you project landing page (master page) and it will extends your DOM and JavaScript Objects.

Comments

Popular posts from this blog

javascript : String.right

javascript : String.left

javascript : .nextAll()