Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 173 Vote(s) - 3.64 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Get current date in Swift 3?

#1
How can I set label.text current date in Swift 3?

I want to print just today to the screen. I did not find how to do that.

In c# is very simple:

var date = DateTime.Now

I need to write 15.09.2016 in swift 3.
thanks


Reply

#2
You can do it in this way with Swift 3.0:

let date = Date()
let calendar = Calendar.current
let components = calendar.dateComponents([.year, .month, .day], from: date)

let year = components.year
let month = components.month
let day = components.day

print(year)
print(month)
print(day)
Reply

#3
You say in a comment you want to get "15.09.2016".

For this, use `Date` and `DateFormatter`:

let date = Date()
let formatter = DateFormatter()

Give the format you want to the formatter:

formatter.dateFormat = "dd.MM.yyyy"

Get the result string:

let result = formatter.string(from: date)

Set your label:

label.text = result

Result:

> 15.09.2016
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through