Javascript UTC date/time bug in Safari?

I have found what I believe is a UTC date/time bug in javascript/Safari. If I get the UTC version of the current date and then 'get' and 'set' the minutes field, the hour advances by one. This happens with Safari but not other browsers on OSX. As a test, I wrote the following html stub to check it out. It may be something to do with the recent change to GMT from UK summer time, but I suspect not....

&<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script language="JavaScript" type="text/javascript">

function datebug() {
var d = new Date(); // current date&time
alert('Local current date/time:\n' + d);
var minutes = d.getMinutes();
d.setMinutes(minutes);
alert('Local current date:\n' + d + ' with minutes got and set');
}

function UTCdatebug() {
var d = new Date(); // current date&time
alert('UTC current date/time:\n' + d);
var minutes = d.getUTCMinutes();
d.setUTCMinutes(minutes);
alert('UTC current date/time:\n' + d + ' with minutes got and set');
}

</script>
</head>

<body>

Safari UTC date bug


<input name="test" type="button" value="date!" onClick="datebug();"/>

<input name="test" type="button" value="UTC date bug!" onClick="UTCdatebug();"/>
</body>
</html>

Posted on Nov 2, 2005 12:39 PM

Reply
5 replies

Nov 3, 2005 2:46 AM in response to iBod

I have now installed 10.4.3 but the bug is still present.

I am installing WebKIT to see if that cures the problem. I hope the next 10.4 upgrade will include the bug fix(es)......

I can't figure out how to include html explicitly in a post. Any ideas? For now the head part is:

function dateOK() {
var d = new Date(); // current date&time
alert('Local current date/time:\n' + d);
var minutes = d.getMinutes();
d.setMinutes(minutes);
alert('Local current date:\n' + d + ' with minutes got and set');
}

function UTCdatebug() {
var d = new Date(); // current date&time
alert('UTC current date/time:\n' + d);
var minutes = d.getUTCMinutes();
d.setUTCMinutes(minutes);
alert('UTC current date/time:\n' + d + ' with minutes got and set');
}

.. and the body part is (add '<'s to the start of the lines):

input name="test" type="button" value="date!" onClick="dateOK();"/>

input name="test" type="button" value="UTC date bug!" onClick="UTCdatebug();"/>

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Javascript UTC date/time bug in Safari?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.