In javascript, by using the method getUTCDate() a error came.
with a datepicker a chose a the date 2013/04/01, but the getUTCDate() returns 31 for the same month and year. By using the method getDate() the return number is 1. seems a bug to me but...
why does this happen?
My UTC+00 -- Portugal
<script>
function myFunction() {
var dataToData = new Date();
dataToData = $("#datepicker").datepicker("getDate"); //ui-jquery datepicker
var yearDpick = "";
var monthDpick = "";
var dayDpick = "";
var monthaux = dataToData.getMonth() + 1;
var dayaux2 = dataToData.getUTCDate();
var dayaux = dataToData.getDate();
yearDpick += dataToData.getFullYear().toString();
if (monthaux > 9) {
monthDpick += monthaux.toString();
} else monthDpick += "0" + monthaux.toString();
if (dayaux > 9) {
dayDpick += dayaux.toString();
} else dayDpick += "0" + dayaux.toString();
alert(dayaux2.toString());
alert(yearDpick+monthDpick+dayDpick);
}
</script>
Because you're not living in UTC. You're probably living in UTC+xx. If you set a date with setDate, don't use getUTCDate later. Keep in mind that new Date() will use your local time instead of UTC if you use a string as argument.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With