I am using the HTML5 element datetime-local. I need to have two formats of the date. One as a date object the other as a string. I am going to store the date object in the database and I am going to use the string to set the datetime-local form input.
I need to convert this string to a date object:
"2014-06-22T16:01"
I can't seem to get the correct time. This is what I am getting. The time not correct.
Sun Jun 22 2014 09:01:00 GMT-0700 (PDT)
This is the how I am formating the date:
function formatTime(_date) {
var _this = this,
    date    = (_date) ? _date : new Date(),
    day     = date.getDate(),
    month   = date.getMonth() + 1,
    year    = date.getFullYear(),
    hour    = date.getHours(),
    minute  = date.getMinutes(),
    seconds = date.getSeconds(),
function addZero(num) {
  return num > 9 ? num : '0' + num;
}
minute  = addZero(minute);
seconds = addZero(seconds);
hour    = addZero(hour);
day     = addZero(day);
month   = addZero(month);
return year + '-' + month + '-' + day + 'T' + hour + ':' + minute;
};