0

Is their any inbuilt method to display date as DD MMM YYYY (08 Jan 2018) format in javascript Currently I am using the below code for date format.

$('#timeTable th:not(:first-child)').each(function(){
                if($(this).attr('Id') === 'totalHours') return;
                $(this).text(dateObj.getDate()+'/'+dateObj.getMonth()+'/'+dateObj.getFullYear());
                dateObj.setDate(dateObj.getDate() + 1);
                }); 

1 Answers1

0

Nothing built in. Your approach is pretty much as good as you'll get without a library.

Note that months are zero indexed, so you need to add one to the result of getMonth.

EDIT

If your program doesn't need to run after the year 9999 you might get away with:

dateObj.toISOString().slice(0, 10);

toISOString produces a value like 2018-01-08T08:52:17.406Z. You can just use the first 10 characters.

Drew Noakes
  • 266,361
  • 143
  • 616
  • 705