ios- Check whether current time is between two times or not
Tag : ios , By : Chandra P Singh
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further I want to check whether the current time is between two time or not. , Try this NSDateComponents *components = [[NSCalendar currentCalendar] components:NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit fromDate:[NSDate date]];
NSInteger currentHour = [components hour];
NSInteger currentMinute = [components minute];
NSInteger currentSecond = [components second];
if (currentHour < 7 || (currentHour > 21 || currentHour == 21 && (currentMinute > 0 || currentSecond > 0))) {
// Do Something
}
|
How to check if the Current Time is in between Two Given TImes?
Date : March 29 2020, 07:55 AM
I wish this help you I have got startTime and endTime and current_time , how to check if the current time is in between these two times or not ?? , Try this code.. This code will convert 12 hr time to 24 hr time. var startTime = '12:27 PM';
var endTime = '12:36 PM';
var curr_time = getval();
if (get24Hr(curr_time) > get24Hr(startTime) && get24Hr(curr_time) < get24Hr(endTime)) {
//in between these two times
alert("Yes")
} else {
alert('No');
}
function get24Hr(time){
var hours = Number(time.match(/^(\d+)/)[1]);
var AMPM = time.match(/\s(.*)$/)[1];
if(AMPM == "PM" && hours<12) hours = hours+12;
if(AMPM == "AM" && hours==12) hours = hours-12;
var minutes = Number(time.match(/:(\d+)/)[1]);
hours = hours*100+minutes;
console.log(time +" - "+hours);
return hours;
}
function getval() {
var currentTime = new Date()
var hours = currentTime.getHours()
var minutes = currentTime.getMinutes()
if (minutes < 10) minutes = "0" + minutes;
var suffix = "AM";
if (hours >= 12) {
suffix = "PM";
hours = hours - 12;
}
if (hours == 0) {
hours = 12;
}
var current_time = hours + ":" + minutes + " " + suffix;
return current_time;
}
|
how to check current date time is in between given date times in iOS?
Date : March 29 2020, 07:55 AM
I wish this help you I'm not sure how you are calculating your startDate and end Date, but to simply calculate if your current date is in between two dates or not, you can do this: Get the dates: NSString *startingDate = @"01-06-2016 20:09:47 PM";
NSString *endingDate = @"08-06-2016 20:09:47 PM";
NSDateFormatter *startForm=[[NSDateFormatter alloc]init];
[startForm setDateFormat:@"dd-MM-yyyy HH:mm:ss a"];
NSDate *startDate = [startForm dateFromString:startingDate];
NSDate *endDate = [startForm dateFromString:endingDate];
case A - (startDateIsOld && !endDateIsOld)
case B- (!startDateIsOld && endDateIsOld)
- (BOOL)isDate:(NSDate *)date inRangeFirstDate:(NSDate *)firstDate lastDate:(NSDate *)lastDate {
BOOL startDateIsOld = false;
BOOL endDateIsOld = false;
if ([date compare:firstDate]==NSOrderedAscending) {
NSLog(@"first date is after current date");
startDateIsOld=NO;
}
if ([date compare:lastDate]==NSOrderedDescending){
NSLog(@"last date is before current date");
endDateIsOld=YES;
}
if ([date compare:firstDate]==NSOrderedDescending) {
NSLog(@"first date is before current date");
startDateIsOld=YES;
}
if ([date compare:lastDate]==NSOrderedAscending){
NSLog(@"last date is after current date");
endDateIsOld=NO;
}
if ((startDateIsOld && !endDateIsOld) || (!startDateIsOld && endDateIsOld) ) {
NSLog(@"date is in range");
return YES;
}
return NO;
}
if ((([date compare:firstDate]==NSOrderedDescending) && ([date compare:lastDate]==NSOrderedAscending)) || (([date compare:firstDate]==NSOrderedAscending) && ([date compare:lastDate]==NSOrderedDescending))) {
NSLog(@"date is in range");
return YES;
}
|
How can I check if the current date/time is past a set date/time in variable time zones?
Tag : php , By : user185751
Date : March 29 2020, 07:55 AM
I wish did fix the issue. Using DateTime, you can specify a time and time zone then compare to the current time: $date = new DateTime('2017-05-05 07:00:00', new DateTimeZone('TimezoneID'));
return ($date->getTimestamp() < time());
|
Check if the current time is between other times
Date : March 29 2020, 07:55 AM
|