This sample demonstrates the use of nn::nlib::DateTime
to calculate and display the date and time.
The rich feature set of the DateTime
class provides a simple way to calculate and display the date and time.
bool SampleDateTime() {
char buf[32];
DateTime now;
DateTime::GetNow(&now);
now.ToRfc2822(buf);
now.ToW3cDtf(buf);
int nth;
now.GetDayOfYear(&nth);
DateTime tmp = now;
e = tmp.AddDays(1000);
if (e != 0) return false;
tmp.ToRfc2822(buf);
tmp = now;
e = tmp.AddDays(-1000);
if (e != 0) return false;
tmp.ToRfc2822(buf);
DateTime dt;
TimeSpan delta;
e = DateTime::Parse("2000-01-01", &dt, &delta);
if (e != 0) return false;
TimeSpan span = now - dt;
int days, seconds;
span.Get(&days, &seconds, NULL, NULL);
nlib_printf(
"Now is %d days and %d seconds from 2000/01/01\n", days, seconds);
return true;
}
bool SampleMain(int, char**) { return SampleDateTime(); }
NLIB_MAINFUNC