- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
XML Date format
Tue, 2011-05-31, 16:38
Hi,I noticed a strange behaviour. when I use the XML literals to write xml document, the Date types sometimes are encoded as yyyy-mm-dd other times as "Sun May 01 00:00:00 CEST 2011" for instance. How is it controlled? Anyone can help me?
Tue, 2011-05-31, 17:07
#2
Re: XML Date format
Isn't that Locale dependent ? Or related to the LONG/SHORT format ?
On Tue, May 31, 2011 at 17:51, Tommaso Galleri <Tommaso.Galleri@bjss.com> wrote:
On Tue, May 31, 2011 at 17:51, Tommaso Galleri <Tommaso.Galleri@bjss.com> wrote:
You probably want to use something like SimpleDateFormat:
val sdf = new java.text.SimpleDateFormat("yyyy-MM-dd")
val dateString = sdf.format(new java.util.Date)
val myXml = <Date>{ dateString }</Date>
println(myXml)
Tommaso
From: scala-user@googlegroups.com [mailto:scala-user@googlegroups.com] On Behalf Of Filippo De Luca
Sent: 31 May 2011 16:38
To: scala-user@googlegroups.com
Subject: [scala-user] XML Date format
Hi,
I noticed a strange behaviour. when I use the XML literals to write xml document, the Date types sometimes are encoded as yyyy-mm-dd other times as "Sun May 01 00:00:00 CEST 2011" for instance. How is it controlled? Anyone can help me?
The information included in this email and any files transmitted with it may contain information that is confidential and it must not be used by, or its contents or attachments copied or disclosed, to persons other than the intended addressee. If you have received this email in error, please notify BJSS. In the absence of written agreement to the contrary BJSS' relevant standard terms of contract for any work to be undertaken will apply. Please carry out virus or such other checks as you consider appropriate in respect of this email. BJSS do not accept responsibility for any adverse effect upon your system or data in relation to this email or any files transmitted with it. BJSS Limited, a company registered in England and Wales (Company Number 2777575), VAT Registration Number 613295452, Registered Office Address, First Floor, Coronet House, Queen Street, Leeds, LS1 2TW
Tue, 2011-05-31, 17:17
#3
RE: XML Date format
v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
I thought he meant long/short formats. For locale-aware then, something like:
val it_df = java.text.DateFormat.getDateInstance(java.text.DateFormat.DEFAULT, java.util.Locale.ITALIAN)
val dateString_it = it_df.format(new java.util.Date)
val us_df = java.text.DateFormat.getDateInstance(java.text.DateFormat.DEFAULT, java.util.Locale.US)
val dateString_us = us_df.format(new java.util.Date)
val myXml = <Date>{ dateString_it }</Date>
println(myXml)
val myXml = <Date>{ dateString_us }</Date>
println(myXml)
First produce: <Date>31-mag-2011</Date>
Second produces: <Date>May 31, 2011</Date>
This is more Java than Scala anyway….
Tommaso
From:
Jan Goyvaerts [mailto:java.artisan@gmail.com]
Sent: 31 May 2011 17:01
To: Tommaso Galleri
Cc: scala-user@googlegroups.com
Subject: Re: [scala-user] XML Date
format
Isn't that Locale dependent ? Or related to the LONG/SHORT format ?
On Tue, May 31, 2011 at 17:51, Tommaso Galleri <Tommaso.Galleri@bjss.com> wrote:
You probably want to use something like SimpleDateFormat:
val sdf = new java.text.SimpleDateFormat("yyyy-MM-dd")
val dateString = sdf.format(new java.util.Date)
val myXml = <Date>{ dateString }</Date>
println(myXml)
Tommaso
From: scala-user@googlegroups.com
[mailto:scala-user@googlegroups.com]
On Behalf Of Filippo De Luca
Sent: 31 May 2011 16:38
To: scala-user@googlegroups.com
Subject: [scala-user] XML Date
format
Hi,
I noticed a strange behaviour. when I use the XML literals to write xml document, the Date types sometimes are encoded as yyyy-mm-dd other times as "Sun May 01 00:00:00 CEST 2011" for instance. How is it controlled? Anyone can help me?
The information included in this email and any files transmitted with it may contain information that is confidential and it must not be used by, or its contents or attachments copied or disclosed, to persons other than the intended addressee. If you have received this email in error, please notify BJSS. In the absence of written agreement to the contrary BJSS' relevant standard terms of contract for any work to be undertaken will apply. Please carry out virus or such other checks as you consider appropriate in respect of this email. BJSS do not accept responsibility for any adverse effect upon your system or data in relation to this email or any files transmitted with it. BJSS Limited, a company registered in England and Wales (Company Number 2777575), VAT Registration Number 613295452, Registered Office Address, First Floor, Coronet House, Queen Street, Leeds, LS1 2TW
Tue, 2011-05-31, 17:38
#4
Re: RE: XML Date format
Hi thanks for the reply,It is a bug actually: https://issues.scala-lang.org/browse/SI-1787
the XML specification permits only (for Date without hours) the format yyyy-MM-dd not dependent by the locale.
the XML specification permits only (for Date without hours) the format yyyy-MM-dd not dependent by the locale.
Tue, 2011-05-31, 19:07
#5
Re: XML Date format
On Tuesday, May 31, 2011 at 9:30 AM, Filippo De Luca wrote:
> the XML specification permits only (for Date without hours) the format yyyy-MM-dd not dependent by the locale.
The XML date format is the 'long' form of the ISO8601 standard. See http://www.w3.org/TR/xmlschema-2/#isoformats and http://en.wikipedia.org/wiki/ISO_8601. In scala you can code the dateTime formatter for it as:
// For dates in UTC
val s = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"))
// For dates in the local time zone
val s = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ")
Cheers
p.s. The alternative to the long form is the compact form which is like 20110531T104800Z (like long form but without the colons and hyphens). The compact form is not used in the XML standards.
You probably want to use something like SimpleDateFormat:
val sdf = new java.text.SimpleDateFormat("yyyy-MM-dd")
val dateString = sdf.format(new java.util.Date)
val myXml = <Date>{ dateString }</Date>
println(myXml)
Tommaso
From: scala-user@googlegroups.com [mailto:scala-user@googlegroups.com] On Behalf Of Filippo De Luca
Sent: 31 May 2011 16:38
To: scala-user@googlegroups.com
Subject: [scala-user] XML Date format
Hi,
I noticed a strange behaviour. when I use the XML literals to write xml document, the Date types sometimes are encoded as yyyy-mm-dd other times as "Sun May 01 00:00:00 CEST 2011" for instance. How is it controlled? Anyone can help me?
The information included in this email and any files transmitted with it may contain information that is confidential and it must not be used by, or its contents or attachments copied or disclosed, to persons other than the intended addressee. If you have received this email in error, please notify BJSS. In the absence of written agreement to the contrary BJSS' relevant standard terms of contract for any work to be undertaken will apply. Please carry out virus or such other checks as you consider appropriate in respect of this email. BJSS do not accept responsibility for any adverse effect upon your system or data in relation to this email or any files transmitted with it. BJSS Limited, a company registered in England and Wales (Company Number 2777575), VAT Registration Number 613295452, Registered Office Address, First Floor, Coronet House, Queen Street, Leeds, LS1 2TW