将字符串“DDMMYY HH:MM”格式化为“YY-MM-DD HH:MM”

时间:2016-03-03 13:35:59

标签: c++ linux

我想使用boost库或任何API将字符串“DDMMYY HH:MM”转换为“YY-MM-DD HH:MM”。

谢谢,

1 个答案:

答案 0 :(得分:3)

最好的选择当然是生成正确的RIGHT字符串,但我不会努力工作以获得一个"库"这样做,因为它真的太过分了......

就是这样的

std::string input = "DDMMYY HH:MM";

std::string output = input.substr(4, 2) + "-" + // YY-
                     input.substr(2, 2) + "-" + // MM-
                     input.substr(0, 2) +     // DD
                     input.substr(6);          //  HH:MM ("the rest")

首先将其作为函数reformat_date包装,并先解释一下。

相关问题