简体   繁体   English

从 Win32 中的字符串解析日期

[英]Parse a Date from a String in Win32

I have a string containing a date, and another string containing the date format of the first string.我有一个包含日期的字符串,另一个包含第一个字符串的日期格式的字符串。 Is there a function that I can call to convert that date into something like a SYSTEMTIME structure?有没有我可以调用的函数将该日期转换为类似 SYSTEMTIME 结构的函数? Basically, I'd like the opposite of GetDateFormat() .基本上,我想要相反的GetDateFormat()

It doesn't do quite what you've described, but I'd start by using COleDateTime::ParseDateTime . 它没有完全按照你所描述的那样做,但我首先使用COleDateTime::ParseDateTime It works with localized date-time formats. 它适用于本地化的日期时间格式。

No, but you can write a function that will convert the date format string into a sscanf format string and series of variables. 不,但您可以编写一个函数,将日期格式字符串转换为sscanf格式字符串和一系列变量。 Then copy the data from the variables to the SYSTEMTIME structure and you're all set. 然后将数据从变量复制到SYSTEMTIME结构,您就完成了所有设置。

It's not trivial, but it is probably the most flexible arrangement if you must support many different date formats. 这不是微不足道的,但如果你必须支持许多不同的日期格式,它可能是最灵活的安排。

If you have a POSIX system, you can use the strptime() function. 如果您有POSIX系统,则可以使用strptime()函数。 Unfortunately, MSVC 2005 does not seem to have this function in its C runtime; 不幸的是,MSVC 2005似乎在它的C运行时没有这个功能; MinGW for Windows does. 适用于Windows的MinGW。

In the source file Here . 在源文件在这里

I have a function that reads dates in a bunch of different formats, the function is called 我有一个函数,以一堆不同的格式读取日期,该函数被调用

bool kGUIDate::Setz(const char *datestring)

It's a class that reads in the day / month / year and also handles hours / minutes / seconds. 这是一个读取日/月/年并且还处理小时/分钟/秒的课程。

The code is LGPL so feel free to copy it. 代码是LGPL,所以随意复制它。

/* formats excepted are: */
/* yyyy-mm-dd */
/* Wdy, DD-Mon-YY HH:MM:SS GMT */
/* Wdy, D Mon YY HH:MM:SS GMT */

是的,只需使用GDF的标准对面win32 api()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM