0

Hi,

How can i calculate time difference in swift 2 between two dates/time and store in 2 different variables, one showing the full difference in terms of "Year, Month, Days, Hours, Minutes" & one variable for converting the total time difference in minutes.

For example-

First Date/time - 04/13/2016 8:11 AM
Current Date/Time - 04/22/2016 12:53 AM

Now one variable should display difference as "8 Day 16 hours & 43 Minutes", if there was a year & month difference, it should show that as well.

And second variable should simply convert "8 Day 16 hours & 43 Minutes" into minutes and should show only a integer for minutes.

Please note that first date can be a future date so it shouldn't display -tive time difference.

Please help.

Thanks
Akhil

3
Contributors
3
Replies
26
Views
2 Years
Discussion Span
Last Post by Zivie_2
0

Convert the date+time into seconds from the "epoch". There are functions to do this in php, java, C/C++, C#, et al. Then you just subtract one from the other to determine the number of seconds between the two values. RTFM.

Votes + Comments
This is fine as it may make the code more portable.
0

Thanks Rubberman, Can you suggest any function in swift 2?

Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.