Object | +---DDateTime
The DDateTime class implements a date & time datatype.
#include <stdio.h> #include "ofc/DDateTime.h" int main(int argc, char *argv[]) { DDateTime *dtm1 = [DDateTime alloc]; DDateTime *dtm2 = [DDateTime new ]; DText *str; [dtm1 init :2008 :7 :20 :15 :3 :45]; // Init with a date and time [dtm2 time :16 :50 :8]; // Set the time [dtm2 date :2007 :12 :31]; // Set the date str = [dtm1 toISO8601]; printf("Date1 in ISO8601 format:%s.\n", [str cstring]); [str free]; [dtm2 localTime]; // Set the date&time with localtime str = [dtm2 toASC]; printf("LocalTime in asctime format:%s.\n", [str cstring]); [str free]; [dtm2 UTCTime]; // Set the date&time with UTC time str = [dtm2 format :"%a, %d-%b-%Y %H:%M:%S %z"]; printf("UTCTime with format:%s.\n", [str cstring]); [str free]; if ([dtm1 compare :dtm2] == 0) // Compare two dates printf("Date1 is equal to date2.\n"); else if ([dtm1 compare :dtm2] < 0) printf("Date1 is smaller than date2.\n"); else printf("Date1 is greater than date2.\n"); [dtm1 free]; // Cleanup [dtm2 free]; return 0; }