]> git.lizzy.rs Git - minetest-m13.git/blob - src/gettime.h
d0d2699d351dc332f1581b8b3f98acf3b03c5ecb
[minetest-m13.git] / src / gettime.h
1 /*
2 Minetest-m13
3 Copyright (C) 2010 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #ifndef GETTIME_HEADER
21 #define GETTIME_HEADER
22
23 #include "common_irrlicht.h"
24
25 /*
26         Get a millisecond counter value.
27         Precision depends on implementation.
28         Overflows at any value above 10000000.
29
30         Implementation of this is done in:
31                 Normal build: main.cpp
32                 Server build: servermain.cpp
33 */
34 extern u32 getTimeMs();
35
36 /*
37         Timestamp stuff
38 */
39
40 #include <time.h>
41 #include <string>
42
43 inline std::string getTimestamp()
44 {
45         time_t t = time(NULL);
46         // This is not really thread-safe but it won't break anything
47         // except its own output, so just go with it.
48         struct tm *tm = localtime(&t);
49         char cs[20];
50         strftime(cs, 20, "%H:%M:%S", tm);
51         return cs;
52 }
53
54
55 #endif