Producing W3C Datetime Format with Timezone in Java

W3C Datetime (also known as ISO 8601) is a standard machine readable way of formatting dates. In its most specific form, dates can be printed with time and time zone in this format:


For example:


It is not as easy to produce dates in this format in Java as it should be. I needed to format dates like this for creating an XML Sitemap file.