PHP: add seconds to a date
If you are using php 5.3+ you can use a new way to do it. <?php $date = new DateTime(); echo $date->getTimestamp(). “<br>”; $date->add(new DateInterval(‘PT674165S’)); // adds 674165 secs echo $date->getTimestamp(); ?>
If you are using php 5.3+ you can use a new way to do it. <?php $date = new DateTime(); echo $date->getTimestamp(). “<br>”; $date->add(new DateInterval(‘PT674165S’)); // adds 674165 secs echo $date->getTimestamp(); ?>
function millisToMinutesAndSeconds(millis) { var minutes = Math.floor(millis / 60000); var seconds = ((millis % 60000) / 1000).toFixed(0); return minutes + “:” + (seconds < 10 ? ‘0’ : ”) + seconds; } millisToMinutesAndSeconds(298999); // “4:59” millisToMinutesAndSeconds(60999); // “1:01” As User HelpingHand pointed in the comments the return statement should be: return ( seconds == 60 … Read more
Brief Description The answer from Brian Ramsay is more convenient if you only want to convert to minutes. If you want Cocoa API do it for you and convert your NSTimeInterval not only to minutes but also to days, months, week, etc,… I think this is a more generic approach Use NSCalendar method: (NSDateComponents *)components:(NSUInteger)unitFlags … Read more
There are several approaches, like keeping track of the system time or using a Clock and counting ticks. But the simplest way is to use the event queue and creating an event every x ms, using pygame.time.set_timer(): pygame.time.set_timer() repeatedly create an event on the event queue set_timer(eventid, milliseconds) -> None Set an event type to … Read more
^(?:(?:([01]?\d|2[0-3]):)?([0-5]?\d):)?([0-5]?\d)$ Explanation: ^ # Start of string (?: # Try to match… (?: # Try to match… ([01]?\d|2[0-3]): # HH: )? # (optionally). ([0-5]?\d): # MM: (required) )? # (entire group optional, so either HH:MM:, MM: or nothing) ([0-5]?\d) # SS (required) $ # End of string
In case you’re restricted to legacy java.util.Date and java.util.Calendar APIs, you need to take into account that the timestamps are interpreted in milliseconds, not seconds. So you first need to multiply it by 1000 to get the timestamp in milliseconds. long seconds = 1320105600; long millis = seconds * 1000; This way you can feed … Read more