3.1.5 Customize Date and Time



Version Info

Minimum Origin Version Required: Origin8 SR0

Remark

This section shows how to get system time, the conversion of Julian date with string, get Year, Month, Date... from Julian date and so on.

More details please reference to the following Origin C Reference section:

Date Time Functions

Get System Date Time

void GetSystemTimeEx()
{
	SYSTEMTIME sysTime;
    GetSystemTime(&sysTime);
 
    char 	lpcstrTime[100];
    if(systemtime_to_date_str(&sysTime, lpcstrTime))
        printf("Today's date & time with your Origin custom date format = \"%s\"\n", lpcstrTime);
    
    char 	lpcstrTimeCustomizeFormat[100];
    WORD 	wFormat = LDF_YYMMDD_AND_HHMMSS_SEPARCOLON;
    if(systemtime_to_date_str(&sysTime, lpcstrTimeCustomizeFormat, wFormat))
        printf("Today's date & time with the specified date format = \"%s\"\n", lpcstrTimeCustomizeFormat);   
}

Convert Julian Date to Customize String

void get_date_string()
{
	// get system time
	SYSTEMTIME st;
    GetSystemTime(&st);
    
    // convert to Julian Date
    double dDate;
    SystemTimeToJulianDate(&dDate, &st);
    
    // convert Julian Date to string
    string strDate = get_date_str(dDate, LDF_SHORT_AND_HHMM_SEPARCOLON);
    out_str(strDate);   
}

Convert String to Julian Date

void str_to_date_ex1()
{
    string strDate = "12/31/2009"; // Use your regional Short Date form

    double db = str_to_date(strDate, LDF_SHORT); 
 
    if(!is_missing_value(db))
    {
        printf("You have entered %s\n", get_date_str(db, LDF_LONG));
    }
    else
        out_str("the string is not recorgnized as a date string");
}