Reformat Javascript date object -


this question has answer here:

i have date object want reformat different date style, having trouble doing so. i've tried .format() , using moment, can't work (.format() throws start.format("yyyy/ddd") not function error , moment seems return unix timestamps no matter do. keep getting invalid date. here fiddle code in (the dates displayed when hover on block of time).

as requested, here actual code:

google.setonloadcallback(drawchart); function drawchart() {   var container = document.getelementbyid('timeline');   var chart = new google.visualization.timeline(container);   var datatable = new google.visualization.datatable();    datatable.addcolumn({ type: 'string', id: 'rowlabel' });   datatable.addcolumn({ type: 'string', id: 'blocklabel' });   datatable.addcolumn({ type: 'date', id: 'start' });   datatable.addcolumn({ type: 'date', id: 'end' });   datatable.addrows([   ["sat 2b", "task 1", new date(2015, 01, 01), new date(2015, 02, 02)],   ["sat 2b", "task 2", new date(2015, 01, 05), new date(2015, 01, 08)],   ["sat 2b", "task 1", new date("2015-03-10 05:10:39.010000"), new date("2015-03-15 05:10:39.010000")],   ["sat 2c", "task 1", new date("2015-04-10 05:10:39.010000"), new date("2015-04-15 05:10:39.010000")]   ]);     var options = {     timeline: { colorbyrowlabel: true }   };     chart.draw(datatable, options);    google.visualization.events.addlistener(chart, 'onmouseover', function(e) {     settooltipcontent(datatable,e.row);   }); }   function settooltipcontent(datatable,row) {    if (row != null) {     var sat = datatable.getvalue(row,0);     var taskid = datatable.getvalue(row,1);     //var start = datatable.getvalue(row,2);     var start = datatable.getvalue(row,2).todatestring();     var startformatted = new date(start, "dd.mm.yyyy hh:mm:ss")     //start.format("dddd, mmmm yyyy, h:mm:ss a");     //start.format('yyyy/ddd-hh:mm:ss');     var end = datatable.getvalue(row,3);      var content = '<div class="custom-tooltip" ><h1>' + sat + ','+ taskid +'</h1><div>' +'start:'+startformatted +', end: '+ end+'</div></div>'; //generate tooltip content     var tooltip = document.getelementsbyclassname("google-visualization-tooltip")[0];     tooltip.innerhtml = content;   } } 

to best of knowledge trying reformat date object i'm not sure going wrong. want display in yyyy/ddd hh:mm:ss format (where ddd day of year).

i figured out. needed use date this:

var start = datatable.getvalue(row,2).todatestring(); var startformatted = moment(start).format("yyyy/ddd hh:mm:ss") 

Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

css - Can I use the :after pseudo-element on an input field? -