Is there any way to get some kind of current date/time info converted to string in one line of code in Swift?
Asked
Active
Viewed 1,199 times
-4
-
formate please ? – Vishal Vaghasiya May 28 '18 at 06:31
-
Please show your tried code. – Khushbu May 28 '18 at 06:32
-
https://stackoverflow.com/questions/24070450/how-to-get-the-current-time-as-datetime – paranjothi May 28 '18 at 06:34
-
https://stackoverflow.com/questions/43199635/get-current-time-as-string-swift-3-0 – Vishnu May 28 '18 at 06:35
-
other formate : https://stackoverflow.com/questions/35700281/date-format-in-swift/43434964#43434964 – Vishal Vaghasiya May 28 '18 at 06:40
-
Do not post pictures of code. Please copy and paste relevant code into your question as text. – rmaddy May 28 '18 at 06:43
-
How is the code not relevant? You've posted a question about an error in your code. If you want help getting your code working then you should post your code as text. Pictures can't be searched or referenced and they are harder to read, not to mention they are harder to put into the question than simply copying and pasting the text. – rmaddy May 28 '18 at 06:59
1 Answers
2
If you just want the current date and time as a string, and you really don’t care about the time zone or the format in any way, this will do:
let nowString = "\(Date())"

TheTiger
- 13,264
- 3
- 57
- 82

rob mayoff
- 375,296
- 67
- 796
- 848
-
@AndrewL. Its strange! Just to know why do you want the date string by this way? – TheTiger May 28 '18 at 07:21
-
@AndrewL. But `"\(Date())"` is not the timestamp. `"\(Date().timeIntervalSince1970)"` is timestamp. – TheTiger May 28 '18 at 10:11