English 中文(简体)
C++的Gregorian 分析二位数年份?
原标题:How can I use boost::gregorian to parse 2-digit years in C++?

推力 :: gregorian:: 从\\\\ string () 来分析 Boost 中的函数似乎只处理 4 位数 的 4 年( 导致 2 位数 年的运行时间错误 ) 。

最清洁的提振方法是什么: : 聚合: 从\\\ string () 函数到进程 2 位数 年?

一种可能性是,结合编程规则在日期字符串上做一些预证,添加2000年或1900年,以净化日期格式,但我不想重塑轮子,如果有更好的办法这样做的话,添加太多代码。

最佳回答

它看起来不像是用推力支持这个格式。 幸运的是, 解析日期格式是单线格式。 下面是用 AXE 撰写的解析器, 我相信您可以在精神中写出类似的代码 。

using namespace boost::gregorian;
using namespace axe::shortcuts;
unsigned year, month, day;
auto date_rule = _uint >> year >  /  > _uint >> month >  /  > _uint >> day > _z;
std::string date_string("99/01/22");
if(date_rule(date_string.begin(), date_string.end()).matched)
{
   date d(year < 100 ? year + 1900 : year, month, day);
   // etc.
}
问题回答

Boost. DateTime 无法做到这一点 — < a href="http://www.boost.org/doc/html/date_time/date_time_io.html#date_time.format_date_time.format_flags" rel=“nofollow”> docs 说有符合你需要的行为的 格式旗帜,但只能用于输出,而不是输入,甚至只能用于有限的平台。





相关问题
Mysql compaire two dates from datetime?

I was try to measure what is faster and what should be the best way to compare two dates, from datetime record in MySql db. There are several approaches how to grab a date from date time, but I was ...

iPhone Date Picker rolls over to 2010 on December 27th?

So I implemented a UIDatepicker in one of my applications for scheduling and autodialing teleconferences... everything is pretty much ready to go except, while testing I noticed that when the date ...

Convert date Python

I have MMDDYY dates, i.e. today is 111609 How do I convert this to 11/16/2009, in Python?

specifying date format when using $form->inputs() in CakePHP

I am wondering if there is a way to specify the date format in the forms created using CakePHP s $form->inputs(); Please note that this is not the individual $form->input() but instead $form->inputs() ...

NSDateFormat, super simple! Where am I screwing up?

Ok, this is really simple, maybe I m a getting a bit burnt out, but seems like it should work, Query XML feed, put out date string, format, display in a cell. The issue is I m a getting a NULL ...

sqlite writing a date into an email

I am exporting a date value from sqlite and placing it into an email. The date appears like this 279498721.322872 I am using Objective C in an Iphone App. Does anyone know how to make this export ...

热门标签