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
 All Forums
 Origin Forum for Programming
 Forum for Origin C
 Problems about time

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
rainlane Posted - 10/10/2017 : 04:07:54 AM
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
3   L A T E S T    R E P L I E S    (Newest First)
Chris D Posted - 10/12/2017 : 12:32:20 PM
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
rainlane Posted - 10/12/2017 : 03:39:00 AM
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
Chris D Posted - 10/10/2017 : 1:13:52 PM
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

The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000