Thread: [Cppcms-users] Parsing time from a string into date_time?
Brought to you by:
artyom-beilis
From: <ele...@ex...> - 2012-04-19 02:07:05
|
Hi, I was wondering if there's a facility to parse a string into date_time. Strings such as YYYY-MM-DD or YY-MM-DD or YYYY-DD-MM or DD/MM/YYYY and so on Thanks! Petr |
From: Marcel H. <ke...@co...> - 2012-04-19 06:39:45
|
Are you serious? Do you know Google, Bing, Yahoo etc? http://www.cplusplus.com/reference/clibrary/ctime/strftime/ .... -- Diese Nachricht wurde von meinem Android-Mobiltelefon mit K-9 Mail gesendet. ele...@ex... schrieb: Hi, I was wondering if there's a facility to parse a string into date_time. Strings such as YYYY-MM-DD or YY-MM-DD or YYYY-DD-MM or DD/MM/YYYY and so on Thanks! Petr _____________________________________________ For Developers, A Lot Can Happen In A Second. Boundary is the first to Know...and Tell You. Monitor Your Applications in Ultra-Fine Resolution. Try it FREE! http://p.sf.net/sfu/Boundary-d2dvs2 _____________________________________________ Cppcms-users mailing list Cpp...@li... https://lists.sourceforge.net/lists/listinfo/cppcms-users |
From: augustin <aug...@ov...> - 2012-04-19 08:00:15
|
On Thursday, April 19, 2012 02:37:59 PM Marcel Hellwig wrote: > http://www.cplusplus.com/reference/clibrary/ctime/strftime/ If I understand well, this function provides a string from a time_t. And if I understand well Petr's original request, he wants the opposite: get a time_t from a string. I'm sure there's an easy solution somewhere, a simple third-party API. In any case, there seem to be a relevant item in CPPCMS' roadmap, even if it's not what was requested either: http://cppcms.com/wikipp/en/page/cppcms_1x_tasks#Implement.Locale.sensitive.Date- Time.Form.Widgets "Implement Locale sensitive Date-Time Form Widgets ICU provides good features for parsing and formatting dates and times, implement Date-Time Widget for this purpose." Blessings, Augustin. -- Friends: http://www.reuniting.info/ My projects: http://astralcity.org/ http://les3enjeux.fr/ http://linux.overshoot.tv/ http://overshoot.tv/ http://charityware.info/ http://masquilier.org/ http://openteacher.info/ http://minguo.info/ http:://jacqueslemaire.fr/ http://www.wechange.org/ http://searching911.info/ . |
From: Artyom B. <art...@ya...> - 2012-04-19 08:26:38
|
To parse date-time read http://www.boost.org/doc/libs/1_49_0/libs/locale/doc/html/formatting_and_parsing.html Just change "boost" to "booster" Note to parse booster::locale::date_time you need to compile CppCMS with ICU. Otherwise you can use booster::ptime and std::tm <-> booster::ptime/time_t conversions. http://cppcms.com/cppcms_ref/latest/classbooster_1_1ptime.html#a5d69b8e68c9847834ee984bfd19be8b5 > not what was requested either: > http://cppcms.com/wikipp/en/page/cppcms_1x_tasks#Implement.Locale.sensitive.Date- > Time.Form.Widgets > "Implement Locale sensitive Date-Time Form Widgets > ICU provides good features for parsing and formatting dates and times, > implement Date-Time Widget for this purpose." Note this mostly related to forms/widgets. CppCMS supports date-time parsing. Artyom Beilis -------------- CppCMS - C++ Web Framework: http://cppcms.com/ CppDB - C++ SQL Connectivity: http://cppcms.com/sql/cppdb/ > |
From: <ele...@ex...> - 2012-04-19 10:45:47
|
On the other hand would this work? ( i don't have a C++ compiler on this windows laptop to try it) double t; istringstream is("2001-12-12"); is >> as::ftime("%Y-%m-%d") >> t; date_time dt(t); Petr |
From: <ele...@ex...> - 2012-04-19 10:34:12
|
Does this work for both string-to-date_time as wells as date_time-to-string? I'm aware of strftime, and all, but that's in reverse. I'm looking for something like time_input_facet that's in boost::posix_time allowing me to parse a string/char into time. Perhaps something like istringstram ss("2001-12-12"); date_time dt; ss >> format("%Y-%m-%d") >> dt; would be really handy. The examples of date and time formatting on the page you pointed out seem to only show output streams (date to string formatting), but maybe I'm not seeing something obvious in which case I apologize. Cheers Petr > To parse date-time read > > > http://www.boost.org/doc/libs/1_49_0/libs/locale/doc/html/formatting_and_parsing.html > > Just change "boost" to "booster" > > Note to parse booster::locale::date_time you need to compile CppCMS with > ICU. > |
From: Artyom B. <art...@ya...> - 2012-04-19 11:19:02
|
> > Does this work for both string-to-date_time as wells as date_time-to-string? > > I'm aware of strftime, and all, but that's in reverse. I'm looking > for > something like time_input_facet that's in boost::posix_time allowing me to > parse a string/char into time. > > Perhaps something like > > istringstram ss("2001-12-12"); > date_time dt; > > ss >> format("%Y-%m-%d") >> dt; > It works, with manipulators: ss >> booster::locale::as::ftime("%Y-%m-%d") >> dt; It requires CppCMS to be compiled with ICU. Artyom |
From: <ele...@ex...> - 2012-04-20 01:47:43
|
Aaah excellent. What happens if the time string doesn't match the format? ie. the time/date is 2001/12/01 and ftime is set to %Y-%m-%d Is there a way to check for such failure(ie. does it throw?) Thanks! Petr > It works, with manipulators: > > ss >> booster::locale::as::ftime("%Y-%m-%d") >> dt; > > It requires CppCMS to be compiled with ICU. > > Artyom > |
From: Artyom B. <art...@ya...> - 2012-04-21 15:31:39
|
>> It works, with manipulators: >> >> ss >> booster::locale::as::ftime("%Y-%m-%d") >> dt; > > Is there a way to check for such failure(ie. does it throw?) > The error is reported as any error in istream parsing: failbit. Read about error handling for C++ I/O stream Artyom |