在 Swift 3 中获取当前日期? [英] Get current date in Swift 3?

查看:72
本文介绍了在 Swift 3 中获取当前日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 Swift 3 中设置 label.text 当前日期?

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.

在c#中很简单:

var date = DateTime.Now

我需要在 swift 3 中写入 15.09.2016.谢谢

I need to write 15.09.2016 in swift 3. thanks

推荐答案

您在评论中说您想获得15.09.2016".

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

为此,使用 DateDateFormatter:

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

给格式化程序提供你想要的格式:

Give the format you want to the formatter:

formatter.dateFormat = "dd.MM.yyyy"

获取结果字符串:

let result = formatter.string(from: date)

设置标签:

label.text = result

结果:

15.09.2016

这篇关于在 Swift 3 中获取当前日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆