Design Pattern Examples
Overview of object-oriented design patterns
datetime.c
Go to the documentation of this file.
1
5
6#include "makelocaltime.h"
7#include "datetime.h"
8
10// datetime_to_string()
12const char* datetime_to_string(time_t timestamp)
13{
14 static char str[128] = { '\0' };
15 struct tm local_time = { 0 };
16 struct tm* timestruct = makelocaltime(&timestamp, &local_time);
17 if (timestruct != NULL)
18 {
19 strftime(str, sizeof(str), "%m/%d/%Y %r", &local_time);
20 }
21 return str;
22}
23
25// datetime_now()
27time_t datetime_now(void)
28{
29 return time(NULL);
30}
time_t datetime_now(void)
Retrieve a time stamp that represents the current time.
Definition: datetime.c:27
const char * datetime_to_string(time_t timestamp)
Convert the specified time stamp to a string.
Definition: datetime.c:12
Declaration of the DateTime class to simplify getting the local time as a string (modeled after the C...
Declaration of the makelocaltime() function to convert a time_t to a struct tm containing the local t...
struct tm * makelocaltime(const time_t *time, struct tm *timestruct)
Convert the given time to local time.
Definition: makelocaltime.c:13