Skip to content

Get the current date and day of the week and the current time

   

Sample code to get the current date, day of the week, and current time in Swift4.1.
You can get it as a string of the following format.

Thu, Apr 03, 2018
19:03:34

Here is the sample code to get it in the form shown above.

If you use Calendar.current, there is a possibility that you will get it in Japanese calendar (Heisei 00 year) depending on the setting (you want 2018/04/03, but 30/04/03 comes back), so it is better to get it in Gregorian calendar.
On the other hand, if you want a Japanese calendar, there is a way to get a Japanese calendar.

This site is detailed.
Swift 3 の日時操作チートシート

Other sites that I found helpful
Swift3での日時に関する処理
【Swift3】現在時刻の取得とDataFormatterでの文字列化

  1. Customize the layout of TableVIew using CustumTableViewCell and accessoryView.
  2. Adding a TextField to UIAlertController
  3. Implementing NavigationController
  4. Generating a QR code from a string or URL
  5. Display an alert with UIAlertController
  6. UIAlertController(UIActionSheet)
  7. Enumerated Type