我在本地Android设备上运行测试。我已经配置了时间间隔。我的时间低于
当地时间: -
Friday 19:37 to Friday 21:38
Saucelabs时间: -
Friday 6:07 to Friday 8:08
当我进行测试时。我期待当地时间到场。但时间不匹配。无论设备/模拟器时间设置如何,如何使用驱动程序实例进行正确比较?
答案 0 :(得分:0)
以下是在IOS中获取当前日期和时间的代码(Objective-C):
NSDate * now = [NSDate date];
NSDateFormatter *outputFormatter = [[NSDateFormatter alloc] init];
[outputFormatter setDateFormat:@"HH:mm:ss"];
NSString *newDateString = [outputFormatter stringFromDate:now];
NSLog(@"newDateString %@", newDateString);
[outputFormatter release];
对于斯威夫特:
let date = NSDate()
let calendar = NSCalendar.currentCalendar()
let components = calendar.components(.CalendarUnitHour | .CalendarUnitMinute, fromDate: date)
let hour = components.hour
let minutes = components.minute
答案 1 :(得分:0)
尝试使用Swift 4: -
func getCurrentTime(){
let strTime: String = "Device Time: " + String(describing: Date())
print(strTime)
}