OSX/Swift: Call function at a specific date/time
By : David Muñoz
Date : March 29 2020, 07:55 AM
hope this fix your issue You could try Grand Central Dispatch. Specifically use dispatch_walltime() to create a dispatch_time_t representing the time you want the job to run and then use dispatch_after() to submit the job to Grand Central Dispatch for execution at the specified time.
|
Convert date string of one time zone to date object in local time Swift
By : Yeisom Gomez
Date : March 29 2020, 07:55 AM
wish help you to fix your issue I want dateString in this format "2016-12-22T08:00:00-08:00" to be converted to date object in users local time for example 2016-12-22 21:30:00 +0530 when the users time is +05:30 from UTC , Fix your dateFormat to: code :
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZZZZZ"
dateFormatter.timeZone = NSTimeZone.local // remove this line
let dateFormatter = DateFormatter()
dateFormatter.dateStyle = .long
dateFormatter.timeStyle = .long
let newString = dateFormatter.string(from: dateObject)
print(newString)
|
Adding time to date picker date and time results in same date and time. SWIFT
By : user2293099
Date : March 29 2020, 07:55 AM
hope this fix your issue There are many problems here. You actually never make any use of dateFormatter other than creating and then never using convertedDate. So delete that unused code. You have indicated at duration should be in minutes but you treat it as seconds. You need to multiply by 60 to convert it to minutes. All of your code for calculating things such as openingTimeQueryEnd depend on each value being two digits but your code doesn't give the desired results. code :
openingTimeQueryEnd = Int("\(String(describing: weekday))"+"\(String(describing: hour))"+"\(String(describing: minute))")!
openingTimeQueryEnd = Int(String(format: "%02d%02d%02d", weekday, hour, minute))!
openingTimeQueryEnd = weekday * 10000 + hour * 100 + minute
|
I have Start Date Time And End Date Time How To Show End Sale in iOS Swift 4
By : user3509261
Date : March 29 2020, 07:55 AM
Hope that helps You should convert the date string to Date first, then you can use timer to update the timer labels based on start and end date. Use Calendar and dateComponents method to find the day, hour, minute and second differences between dates and then set the value on day, hour, minute and second labels as like you attached image. code :
var timer:Timer?
var endDate:Date?
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
startTimer()
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
stopTimer()
}
func startTimer(){
let endDateStr = "Dec 27, 2019 11:15:39 +0000"
let dateFormat = "MMM d, yyyy HH:mm:ss Z"
let dateFormater = DateFormatter()
dateFormater.dateFormat = dateFormat
endDate = dateFormater.date(from: endDateStr)
//stop timer if it's already running
stopTimer()
timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(updateSaleTime), userInfo: nil, repeats: true)
}
func stopTimer(){
if timer != nil{
timer!.invalidate()
timer = nil
}
}
func updateSaleTime(){
guard let d2 = endDate else {
stopTimer()//Check if the date-format is correct for end date string.
return
}
let cal = Calendar.current
let components = cal.dateComponents([.day, .hour, .minute, .second], from: Date(), to: d2)
let day = components.day!
let hour = components.hour!
let minute = components.minute!
let second = components.second!
//set the value on day, hour, minute and second labels as like you attached image.
}
|
How to get actual real Date&Time in iOS Swift? Even when user has changed Date&Time from device setting
By : Alibek Toxambayev
Date : March 29 2020, 07:55 AM
Hope that helps If the device is offline (not connected to any network), you cannot get the “real actual time”. You can only get the system’s idea of the time, and that is under user control.
|