I need to format my date like this "2016-04-19T03:35:17.02". How can i format date format like using javascript or jQuery.
Please help me any one this.
I need to format my date like this "2016-04-19T03:35:17.02". How can i format date format like using javascript or jQuery.
Please help me any one this.
In javascript you have a Date object. First you must create the object:
var d = new Date();
Then you can make a variable for each of the pieces you want:
// Get the year
var year = d.getFullYear();
// Get the month +1 because normally returns 0-11
var month = d.getMonth()+1;
// Format month to add a 0 if 1-9
var fMonth = month < 9 ? '0' + month : month;
// Get day and format it to add a 0 if 1-9
var fDay = d.getDate() < 9 ? '0' + d.getDate() : d.getDate();
// Combine it into a single string
var dateStr = year +'-'+ fMonth +'-'+ fDay +'T';
That should get you "2016-05-22T". The rest you can complete on your own. You can use w3schools list of available Date methods: http://www.w3schools.com/jsref/jsref_obj_date.asp