What was that date again?

For many of us, dates and times are absolutely essential in our daily lives. We make appointments, set deadlines, celebrate birthdays and anniversaries, and generally mark time using clocks and calendars.

What makes dates and times interesting from a programmer’s perspective is that while there is a standard time (the Coordinated Universal Time or UTC), there are multiple local time zones in use all over the world. A single instance in UTC has many local equivalents, and offsets between time zones and universal time are wild and wonderful.

Not only are time zones a little tricky, but there are also multiple local representations for an instance in local time. A representation in this context means the way it is printed in a daily newspaper, in the calendar, and indeed, on the screen of a computer or a mobile device. In the realm of internationalization (I18N) they are known as date and time formats.

The conventions for showing local time are well established, and the differences between them are significant enough to cause a lot of confusion if care is not taken. While it would be the most logical thing to do (thank you Mr. Spock), it is hardly practical to expect all the world’s population to adopt a single standard date and time format such as the ISO 8601 international standard notation in their daily lives. The national and linguistic conventions are very well established locally.

Just recently, Nokia launched new Windows Phone devices in their Lumia series. The company wanted to build anticipation before the announcement with short teaser videos which all marked the date of the launch: 05.09.2012. If you saw this date advertised early in the year, you might think it could mean either September 5th or May 9th this year. But which is it? 

Because the teaser videos appeared in late August and early September, with May already passed, it helped to establish September as the most likely choice. Still, confusion ensued. Here are some actual comments about one of the videos on YouTube (the names have been removed to protect the confused):

  • May 9, 2012 already passed. (xxx 2 days ago)
  • -_- it’s date European DD/MM/YYYY (xxx in reply to xxx 2 days ago)
  • Day/Month/Year. (xxx in reply to xxx 2 days ago)
  • Other way round. 5th September 2012. (xxx in reply to xxx 2 days ago)

Nokia is a Finnish company, and often emphasizes that. However, the date 05.09.2012 is a curious choice, as it is not even the recommended Finnish date format. (For the record, that would be 5.9.2012, without the leading zeros.) This date uses dots as separator characters, whereas people in the United States are used to seeing forward slashes, and the customary U.S. date format has the month first, then the day, with just two digits for the year – that is, 9/5/12. (And surely you have heard the expression “nine eleven” more times than you care to think.)

What a mess, then. And yes, there are other date and time formats out there, with the potential for confusion. As a software developer, what can you do? What should you do?

The best practice is to store all date and time instances in binary form, as seconds or milliseconds from some epoch (for example, a UNIX timestamp is an integer with the number of seconds since January 1, 1970). Whenever you need to generate a textual representation, use the services of your operating system to format the binary date into something you can print out or put in a label in your user interface. This ensures that the time and date is represented to the user in a way that looks familiar to them, almost automatically and based on the settings in their computer or other device.

Never, ever store dates and times in a textual format, unless you know about the ISO 8601 standard format and know how to use it. There are trade-offs, of course: the standard format is more verbose, but it is more descriptive (some say it is even too much so). A binary timestamp is much more compact, but less portable (because there is often confusion about whether the timestamp represents milliseconds or seconds, what is the epoch, and is it UTC or some local time).

Need some help with all that? We can coach you in making your applications truly international, with our expertise in mobile apps for iOS, Android and Windows Phone. Have a look at our services and contact us.