]> wimlib.net Git - wimlib/blob - src/timestamp.c
ebe57380203d1fa956cf114bcc39c216c48fdd19
[wimlib] / src / timestamp.c
1 /*
2  * timestamp.c
3  */
4
5 /*
6  * Copyright (C) 2012, 2013 Eric Biggers
7  *
8  * This file is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU Lesser General Public License as published by the Free
10  * Software Foundation; either version 3 of the License, or (at your option) any
11  * later version.
12  *
13  * This file is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License
19  * along with this file; if not, see http://www.gnu.org/licenses/.
20  */
21
22 #ifdef HAVE_CONFIG_H
23 #  include "config.h"
24 #endif
25
26 #include "wimlib/types.h"
27 #include "wimlib/timestamp.h"
28
29 #include <time.h>
30 #include <sys/time.h>
31
32 u64
33 get_wim_timestamp(void)
34 {
35         struct timeval tv;
36         gettimeofday(&tv, NULL);
37         return timeval_to_wim_timestamp(tv);
38 }
39
40 void
41 wim_timestamp_to_str(u64 timestamp, tchar *buf, size_t len)
42 {
43         struct tm tm;
44         time_t t = wim_timestamp_to_unix(timestamp);
45         gmtime_r(&t, &tm);
46         tstrftime(buf, len, T("%a %b %d %H:%M:%S %Y UTC"), &tm);
47 }
48