Last active
December 12, 2015 09:19
-
-
Save djleeds/4751082 to your computer and use it in GitHub Desktop.
Converting an HTML5 Date Picker value to a JavaScript Date object might not produce the result you expect. These gists demonstrate how you can create the Date object at GMT or your local time zone.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
$(document).ready(function() { | |
$("#execute").bind("click", function() { | |
var dateString = $("#date").val(); | |
var date = new Date(dateString); | |
$("#dateObject").text(date.toString()); | |
}); | |
}); | |
</script> | |
<input id="date" type="date" name="date1" value="2013-02-14" /> | |
<input id="execute" type="button" value="Create Date object" /> | |
<span id="dateObject">(date will dump here)</span> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
$(document).ready(function() { | |
$("#execute").bind("click", function() { | |
var dateString = $("#date").val().replace(/-/g, "/"); | |
var date = new Date(dateString); | |
$("#dateObject").text(date.toString()); | |
}); | |
}); | |
</script> | |
<input id="date" type="date" name="date1" value="2013-02-14" /> | |
<input id="execute" type="button" value="Replace hyphens and create Date object" /> | |
<span id="dateObject">(date will dump here)</span> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment