-3

I am running test in Local Android device. I have configured time interval. My timings are below

Local time:-

Friday 19:37  to Friday 21:38

Saucelabs time:-

Friday 6:07  to Friday 8:08  

When I ran test. I am expecting local time to be present. But time are mismatching. How can I do comparison properly using driver instance irrespective of device / simulator time settings ?

Galet
  • 4,039
  • 12
  • 62
  • 119

2 Answers2

0

Here is the code for Get current Date and time in 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];

And for Swift :

let date = NSDate()
let calendar = NSCalendar.currentCalendar()
let components = calendar.components(.CalendarUnitHour | .CalendarUnitMinute, fromDate: date)
let hour = components.hour
let minutes = components.minute
Mihir Oza
  • 2,633
  • 3
  • 30
  • 56
0

Try in Swift 4:-

func getCurrentTime(){

    let strTime: String = "Device Time: " + String(describing: Date())

    print(strTime)
} 
Deepak Tagadiya
  • 1,821
  • 11
  • 27