The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 Forum for Origin C
 Problems about time
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

rainlane

China
22 Posts

Posted - 10/10/2017 :  04:07:54 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver. and Service Release (Select Help-->About Origin): OriginPro 2017
Operating System: Windows 7 64bit


void    get_date_str_ex1()
{
    SYSTEMTIME st;
    GetSystemTime(&st);              // gets current time, 
    // need to convert to local time
    FILETIME ft, ftLocal;
    SystemTimeToFileTime(&st, &ft);
    FileTimeToLocalFileTime(&ft, &ftLocal);
    FileTimeToSystemTime(&ftLocal, &st);
    double dDate;
    SystemTimeToJulianDate(&dDate, &st);
    out_str(get_date_str(dDate, LDF_SHORT_AND_HHMMSS_SEPARCOLON));
}


I can get the current date and time using this function.

How do I calculate the number of seconds that the specified date and time are different from the current date and time?

forum

Chris D

428 Posts

Posted - 10/10/2017 :  1:13:52 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

Do you need to use the datetimes for any other purpose than to simply calculate the difference in seconds? That is, do you plan to do something with the converted string?

Also, are you interested in rounding to whole seconds or getting fractional seconds?

Thanks,
Chris Drozdowski
Originlab Technical Support
Go to Top of Page

rainlane

China
22 Posts

Posted - 10/12/2017 :  03:39:00 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
In fact, I just want to use the rounding method to get the current time and the specified time difference between the number of seconds.
quote:
Originally posted by Chris D

Hi,

Do you need to use the datetimes for any other purpose than to simply calculate the difference in seconds? That is, do you plan to do something with the converted string?

Also, are you interested in rounding to whole seconds or getting fractional seconds?

Thanks,
Chris Drozdowski
Originlab Technical Support




forum
Go to Top of Page

Chris D

428 Posts

Posted - 10/12/2017 :  12:32:20 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

I believe that what you want is to determine the number of seconds that have passed since now and a date time in the past that is represented as a string. Here is one way to do it that utilizes Julian Dates which are double type variables explained as:

"Origin uses a 12 hour offset from the Astronomical Julian Day Number as 0 (January 1, 4713 BCE 12:00 AM). No assumptions are made about time zones or any time shifting scheme (such as Daylight Savings). For example, 11 June 1998 at 21:23:01 has an Origin Julian Day Number of 2450975.890984. "

A Julian Date is a double type where the integer part is the number of days that have past since the date mentioned above and the fraction part is the fraction of days.


void TestSeconds()
{
	// Get right now as a Julian Date.
	double dNow = NowAsJulian();

	// Create some sort of date time string from past and convert it to Julian Date.
	string strThen = "10/12/2017 12:19:00";
	double dThen;
	str_to_date_custom(strThen, "MM/dd/yyyy HH:mm:ss", &dThen);

	// Subtract the two Julian Dates, multiply by 86400 to get seconds and round to 0 decimal places.
	double dSeconds = round((dNow - dThen)*86400, 0);
	out_double("Seconds=", dSeconds);
}

// Get current datetime in Julian Date
double NowAsJulian()
{
	time_t ltime;
	time( <ime );
	
	TM* tmNow = localtime( <ime );

	SYSTEMTIME SysTime; 
	tm_to_systemtime(tmNow, &SysTime);	
    
    double date;
    SystemTimeToJulianDate(&date, &SysTime); 
    return date;
}


Thanks,
Chris Drozdowski
Originlab Technical Support
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000