GRASS GIS 7 Programmer's Manual
7.8.4(2020)-exported
date.c
Go to the documentation of this file.
1
/*!
2
* \file lib/gis/date.c
3
*
4
* \brief GIS Library - Date functions.
5
*
6
* (C) 2001-2009 by the GRASS Development Team
7
*
8
* This program is free software under the GNU General Public License
9
* (>=v2). Read the file COPYING that comes with GRASS for details.
10
*
11
* \author Original author CERL
12
*/
13
14
#include <time.h>
15
#include <grass/gis.h>
16
17
/*!
18
* \brief Current date and time.
19
*
20
* Returns a pointer to a string which is the current date and
21
* time. The format is the same as that produced by the UNIX
22
* <tt>date</tt> command.
23
*
24
* \return pointer to a string holding date/time
25
*/
26
const
char
*
G_date
(
void
)
27
{
28
static
int
initialized;
29
static
char
*date;
30
time_t clock;
31
struct
tm *local;
32
char
*tdate;
33
char
*d;
34
35
if
(
G_is_initialized
(&initialized))
36
return
date;
37
38
time(&clock);
39
40
local =
localtime
(&clock);
41
tdate = asctime(local);
42
for
(d = tdate; *d; d++)
43
if
(*d ==
'\n'
)
44
*d = 0;
45
46
date =
G_store
(tdate);
47
48
G_initialize_done
(&initialized);
49
50
return
date;
51
}
G_store
char * G_store(const char *s)
Copy string to allocated memory.
Definition:
strings.c:86
G_is_initialized
int G_is_initialized(int *p)
Definition:
counter.c:59
G_initialize_done
void G_initialize_done(int *p)
Definition:
counter.c:76
localtime
struct tm * localtime()
G_date
const char * G_date(void)
Current date and time.
Definition:
date.c:26
gis
date.c
Generated on Sun Dec 13 2020 08:41:19 for GRASS GIS 7 Programmer's Manual by
1.8.20