To find the current date in Swift, you can use the Date()
constructor which creates a new instance of the Date
object set to the current date and time. Here's an example:
main.swift25 chars2 lines
However, keep in mind that Date()
retrieves the current time according to the device's CLOCK. This could lead to incorrect/inaccurate time representation due to device's clock offset.
It's usually best practice to manipulate timezones using a Calendar instance.
main.swift281 chars10 lines
This will print the current date in the format "day-month-year".
gistlibby LogSnag