我希望生成一个新NSDate的0小时,0分钟和0秒的时间.源日期可以是任意的NSDate.
有没有办法实现这个目标?文档对我没有帮助.
例
有: 2010-10-30 10:14:13 GMT
想: 2010-10-30 00:00:00 GMT
我收到一个错误:"在调用中缺少参数'coder'的参数"以获取以下代码:
var components = NSDateComponents()
components.setValue(1,forComponent: NSCalendarUnit.CalendarUnitMonth);
var expirationDate = NSCalendar.currentCalendar().dateByAddingComponents(components, toDate: NSDate(),options:0)
Run Code Online (Sandbox Code Playgroud)
文档要求:
NSCalendar.currentCalendar().dateByAddingComponents(<#comps: NSDateComponents?#>, toDate: <#NSDate?#>, options: <#NSCalendarOptions#>)
Run Code Online (Sandbox Code Playgroud)
任何人都能看到我错过的东西吗?我没有看到名为'coder'的参数需要.
我使用此代码获取当前日期和时间
let today: NSDate = NSDate()
let dateFormatter: NSDateFormatter = NSDateFormatter()
dateFormatter.timeStyle = NSDateFormatterStyle.MediumStyle
dateFormatter.dateFormat = "yyyy-MM-dd hh:mm:ss"
dateFormatter.timeZone = NSTimeZone(abbreviation: "SGT");
print(dateFormatter.stringFromDate(today))
Run Code Online (Sandbox Code Playgroud)
但我想得到今天约会的开始时间和结束时间
例如:
12-09-2016 00:00:00 AND 12-09-2016 23:59:59
如何获取当前日期的开始和结束时间?
我有格式的数据
时间:13:52,10:30,11:48
等等
我想绕到最近的一小时.
比如13:52 - > 14:00,10:30 - > 11:00和11:48 - > 12:00.
我怎么能用NSDate做到这一点?