• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Calculate the time difference using difftime yields unexpected result
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Calculate the time difference using difftime yields unexpected result


  • Subject: Calculate the time difference using difftime yields unexpected result
  • From: Alexander Hartner <email@hidden>
  • Date: Thu, 8 Mar 2007 01:28:25 +0000

I am trying to calculate the time it took for a certain task, so I tried to use difftime, as shown in the example below. Yet when I try to use difftime the result is much larger then I would expect. I also tried simply subtracting the to time measurements from each other and get a much better result. The man page says that I should get the difference in seconds, which is exactly what I am looking for.

Here is the example :

	time_t startTime = time(nil);

	...do some work here

	time_t endTime = time(nil);
	NSLog(@"START TIME : %s",ctime(&startTime));
	NSLog(@"END   TIME : %s",ctime(&endTime));
	NSLog(@"PERIOD     : %d",(endTime-startTime));
	double period = difftime(endTime,startTime);
	NSLog(@"PERIOD DIFF: %d",period);		

OUTPUT:
2007-03-08 01:23:21.497 Address Book 4 Everyone[8349] START TIME : Thu Mar 8 01:23:14 2007
2007-03-08 01:23:21.497 Address Book 4 Everyone[8349] END TIME : Thu Mar 8 01:23:21 2007
2007-03-08 01:23:21.497 Address Book 4 Everyone[8349] PERIOD : 7
2007-03-08 01:23:21.497 Address Book 4 Everyone[8349] PERIOD DIFF: 1075576832

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Calculate the time difference using difftime yields unexpected result
      • From: Brian Stern <email@hidden>
    • Re: Calculate the time difference using difftime yields unexpected result
      • From: Sherm Pendley <email@hidden>
  • Prev by Date: NSURLCredentials properly loading for non-HTTP URLs?
  • Next by Date: What is the easy way to plot data?
  • Previous by thread: NSURLCredentials properly loading for non-HTTP URLs?
  • Next by thread: Re: Calculate the time difference using difftime yields unexpected result
  • Index(es):
    • Date
    • Thread