My input field requires users to select a date and time. The local machine is either in GMT or BST depending on the time of year.
For those unfamiliar with UK time changes:
GMT (Greenwich Mean Time) is always equal to UTC
BST (British Summer Time) is GMT+1 during summer months
The dates entered by users are stored in a database set to GMT, without adjusting for time offsets. Therefore, I need to convert what the user enters into GMT / UTC.
However, my conversions keep returning the same date.
What could be causing this issue?
https://jsfiddle.net/r68owagL/
Below is the code snippet from the jsFiddle:
function log(obj) {
var html = "<table>"
for(var member in obj)
{
html += "<tr>"
+ "<td>" + member + ": </td>"
+ "<td>" + obj[member].format("YYYY-MM-DD HH:mm:ss") + "</td>"
+ "</tr>";
}
html += "</table>";
document.body.innerHTML = html;
}
var strDate = '2016-07-14 10:51:00';
var obj = {
n: moment(strDate), //Gives: 2016-07-14 10:51:00
u: moment.utc(strDate), //Gives: 2016-07-14 10:51:00
b: moment.tz(strDate, "Europe/London") //Gives: 2016-07-14 10:51:00
}
log(obj);