Java getHours(), getMinutes() and getSeconds()

Try this: Calendar calendar = Calendar.getInstance(); calendar.setTime(yourdate); int hours = calendar.get(Calendar.HOUR_OF_DAY); int minutes = calendar.get(Calendar.MINUTE); int seconds = calendar.get(Calendar.SECOND); Edit: hours, minutes, seconds above will be the hours, minutes and seconds after converting yourdate to System Timezone!

How do I get hour and minutes from NSDate?

Use an NSDateFormatter to convert string1 into an NSDate, then get the required NSDateComponents: Obj-C: NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@”<your date format goes here”]; NSDate *date = [dateFormatter dateFromString:string1]; NSCalendar *calendar = [NSCalendar currentCalendar]; NSDateComponents *components = [calendar components:(NSCalendarUnitHour | NSCalendarUnitMinute) fromDate:date]; NSInteger hour = [components hour]; NSInteger minute = [components minute]; … Read more

Add ‘x’ number of hours to date

You may use something like the strtotime() function to add something to the current timestamp. $new_time = date(“Y-m-d H:i:s”, strtotime(‘+5 hours’)). If you need variables in the function, you must use double quotes then like strtotime(“+{$hours} hours”), however better you use strtotime(sprintf(“+%d hours”, $hours)) then.