From: Jon H. L. <jhl...@vi...> - 2013-01-23 11:56:37
|
Hi there, back to the list with some more issues. This time referring to dates and times. I seem not to understand very well how to parse an incoming date, time or datetime string. The problem I will face is the following. Say my input string is "20/12/2012" and I need to yield the ISO 8601-compliat version of this: "2012-12-20". The same applies to time strings: having "22.30" as the input, I would need to yield "22:30". I have been looking at the related documentation, namely: http://userguide.icu-project.org/formatparse/datetime http://userguide.icu-project.org/datetime http://www.icu-project.org/apiref/icu4c/classicu_1_1DateFormat.html http://icu-project.org/apiref/icu4c/classSimpleDateFormat.html And also at the mailing list archives. A related thread as this one: Re: [icu-support] SimpleDateFormat::parse() behavior with ICU4C 49.1.2* *May be there are other places I should look at or it is self-explaining, but I am kind of confused. One of the questions I have is about parsing. Do I need to tell ICU which is the format of the input string so that it can detect the year, month and day? If so, how can I specify this for "20/12/2012"? According to http://userguide.icu-project.org/formatparse/datetime, I should know the locale and the SHORT, MEDIUM, LONG or FULL property about the input date string, isn't it? Is that enough? Thanks again, JON HAITZ <http://www.vicomtech.org/> Jon Haitz Legarreta GorroñoIkertzailea / Investigador / Researcher eOsasuna eta Aplikazio Biomedikoak / eSalud y Aplicaciones Biomedicas / eHealth & Biomedical Applications Donostia - San Sebastián - Spain<http://www.vicomtech.es/castellano/html/contacto/index.html> <http://www.vicomtech.org/> Tel: +[34] 943 30 92 30j...@vi... Aviso Legal - Política de privacidad<http://www.vicomtech.es/castellano/html/informacion_legal/index.html>/ Lege Oharra - Pribatutasun politika<http://www.vicomtech.es/euskera/html/informacion_legal/index.html>/ Legal Notice - Privacy policy<http://www.vicomtech.es/ingles/html/informacion_legal/index.html> |
From: <yos...@us...> - 2013-01-24 21:28:13
|
> One of the questions I have is about parsing. Do I need to tell ICU > which is the format of the input string so that it can detect the > year, month and day? > > If so, how can I specify this for "20/12/2012"? Use SimpleDateFormat with pattern "d/M/y" (or "dd/MM/yyyy" - in this specific case, width of fields does not matter) for this case. > According to http://userguide.icu-project.org/formatparse/datetime, > I should know the locale and the SHORT, MEDIUM, LONG or FULL > property about the input date string, isn't it? Is that enough? In general, parsing text representation of date or time is error prone. Many folks prefer to use UI widgets to take date/time inputs. Some other folks explicitly specify pattern along with text field (such as "yyyy/mm/dd"). I know there are some folks trying to support direct text inputs by using multiple ICU SimpleDateFormat instances with possible patterns in priority order. ICU implementation provides a certain level of leniency in parsing, but a single SimpleDateFormat instance is usually not sufficient to handle all reasonable variations. -Yoshito |
From: Jon H. L. <jhl...@vi...> - 2013-01-25 13:30:41
|
Dear Yoshito, thanks for your answer. OK. Makes things clearer. As for the UI, yes, it would be a lot easier that way. But there is virtually no UI in my application: the input will be parsed documents. Kind regards, JON HAITZ <http://www.vicomtech.org/> Jon Haitz Legarreta GorroñoIkertzailea / Investigador / Researcher eOsasuna eta Aplikazio Biomedikoak / eSalud y Aplicaciones Biomedicas / eHealth & Biomedical Applications Donostia - San Sebastián - Spain<http://www.vicomtech.es/castellano/html/contacto/index.html> <http://www.vicomtech.org/> Tel: +[34] 943 30 92 30j...@vi... Aviso Legal - Política de privacidad<http://www.vicomtech.es/castellano/html/informacion_legal/index.html>/ Lege Oharra - Pribatutasun politika<http://www.vicomtech.es/euskera/html/informacion_legal/index.html>/ Legal Notice - Privacy policy<http://www.vicomtech.es/ingles/html/informacion_legal/index.html> On 24 January 2013 22:27, <yos...@us...> wrote: > > One of the questions I have is about parsing. Do I need to tell ICU > > which is the format of the input string so that it can detect the > > year, month and day? > > > > If so, how can I specify this for "20/12/2012"? > > Use SimpleDateFormat with pattern "d/M/y" (or "dd/MM/yyyy" - in this > specific case, width of fields does not matter) for this case. > > > > According to http://userguide.icu-project.org/formatparse/datetime, > > I should know the locale and the SHORT, MEDIUM, LONG or FULL > > property about the input date string, isn't it? Is that enough? > > In general, parsing text representation of date or time is error prone. > > Many folks prefer to use UI widgets to take date/time inputs. > Some other folks explicitly specify pattern along with text field (such as > "yyyy/mm/dd"). > I know there are some folks trying to support direct text inputs by using > multiple ICU SimpleDateFormat instances with possible patterns in priority > order. ICU implementation provides a certain level of leniency in parsing, > but a single SimpleDateFormat instance is usually not sufficient to handle > all reasonable variations. > > -Yoshito > > > ------------------------------------------------------------------------------ > Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS, > MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current > with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft > MVPs and experts. ON SALE this month only -- learn more at: > http://p.sf.net/sfu/learnnow-d2d > _______________________________________________ > icu-support mailing list - icu...@li... > To Un/Subscribe: https://lists.sourceforge.net/lists/listinfo/icu-support > Archives/Project Info: http://site.icu-project.org/contacts > > |