I am trying to convert the text of a datetime field from UTC to a more American friendly format.
I am having trouble getting the text to change to the converted version. I have each input of type=datetime-local assigned to a class dateTime and I am using the function below.
The code runs without error, but the text of the control is not updated.
Any ideas? Thanks for the help.
- $('.dateTime').click(function() {
- var mainParts = $(this).attr('value').split('T');
- if (mainParts.length > 1) {
- var dateParts = mainParts[0].split('-');
- var timeParts = mainParts[1].split(':');
- var amPm;
- if (parseInt(timeParts[0] > 12)) {
- timeParts[0] = parseInt(timeParts[0]) - 12;
- amPm = 'PM';
- }
- else
- amPm = 'AM';
- $(this).value = dateParts[1] + '/' + dateParts[2] + '/' + dateParts[0] + ' ' + timeParts[0] + ':' + timeParts[1] + ' ' + amPm;
- }
- });