LoginSignup
0
0

More than 3 years have passed since last update.

C > datetime > 2019/06/31をstrptime()はどう扱うか > 2019/06/31として格納 | mktime()だと2019/06/31は2019/07/01になる | C++20 std::chronoのカレンダ

Last updated at Posted at 2019-08-13
動作環境
C++ Builder 10.2 Tokyo
C (gcc 8.3) @ ideone

C++ BuilderでのエラーとCのエラー

C++ Builder 10.2 Tokyoにおいて、EncodeDate(2019, 6, 31)はエラーになる。

一方で、strftime()に関してはどういうことになるかを確認した。

man

実装

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

int main(void) {
    struct tm tm;
    char buf[255];

    memset(&tm, 0, sizeof(struct tm));
    strptime("2019-06-31", "%Y-%m-%d", &tm);
    strftime(buf, sizeof(buf), "%d %b %Y %H:%M", &tm);
    printf("%s\n", buf);

    return 0;
}
stdout
31 Jun 2019 00:00

6/31として格納された。

教えていただきました

@SaitoAtsushi さんのコメントにてmktime を教えていただきました。

情報感謝です。

@yumetodo さんのコメントにてC++20のstd::chronoのカレンダについて教えていただきました。

情報感謝です。

0
0
4

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0