gpt4 book ai didi

c++ - 将字符串 "DDMMYY HH:MM"格式化为 "YY-MM-DD HH:MM"

转载 作者:太空宇宙 更新时间:2023-11-04 04:40:37 24 4
gpt4 key购买 nike

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

谢谢

最佳答案

最好的选择当然是首先生成正确的字符串,但我不会努力让“库”来做到这一点,因为它真的太多了......

就是这样

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,首先进行一些解释。

关于c++ - 将字符串 "DDMMYY HH:MM"格式化为 "YY-MM-DD HH:MM",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35773696/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com