SwiftCommon之日期Date

概述

获取当前系统时间是开发中经常用到的,在IOS中,我们可以使用NSDate创建一个日期时间对象,然后使用NSDateFormatter类指定相应的格式。

比如yyyy-MM-dd HH:mm格式是最常用的。

SCDate

import Foundation /** * 日期与时间类 */ public class SCDate{ /** 获取指定格式的NSDateFormatter对象 :param: forMatterString 日期或者时间格式,比如:yyyy-MM-dd :returns: <#return value description#> */ public class func getDateFormatter(#forMatterString:String) -> NSDateFormatter { var format:NSDateFormatter = NSDateFormatter() format.dateFormat = forMatterString return format } /** 通过指定的DateFormatter获取日期或者时间字符串 :param: dateFormatter 指定的NSDateFormatter对象 :returns: <#return value description#> */ public class func getDateStringFromDateFormatter(dateFormatter:NSDateFormatter)->String{ return dateFormatter.stringFromDate(NSDate()) } /** 获取当前日期和时间(yyyy-MM-dd HH:mm) :returns: <#return value description#> */ public class func getCurrentDateTime()->String{ return getDateStringFromDateFormatter(getDateFormatter(forMatterString: "yyyy-MM-dd HH:mm")) } /** 获取当前日期(yyyy-MM-dd) :returns: <#return value description#> */ public class func getCurrentDate()->String{ return getDateStringFromDateFormatter(getDateFormatter(forMatterString: "yyyy-MM-dd")) } /** 获取当前时间(HH:mm) :returns: <#return value description#> */ public class func getCurrentTime()->String{ return getDateStringFromDateFormatter(getDateFormatter(forMatterString: "HH:mm")) } }

Git地址

http://devonios.com/go/swiftcommon

tips:

本文由wp2blog导入,原文链接:http://devonios.com/scdate.html

点赞
收藏

评论区

加载中...

相关推荐

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

一篇文章带你了解JavaScript日期

日期对象允许您使用日期(年、月、日、小时、分钟、秒和毫秒)。一、JavaScript的日期格式一个JavaScript日期可以写为一个字符串:ThuFeb02201909:59:51GMT0800(中国标准时间)或者是一个数字:1486000791164写数字的日期,指定的毫秒数自1970年1月1日00:00:00到现在。1\.显示日期使用

皕杰报表(关于日期时间时分秒显示不出来)

在使用皕杰报表设计器时,数据据里面是日期型,但当你web预览时候,发现有日期时间类型的数据时分秒显示不出来,只有年月日能显示出来,时分秒显示为0:00:00。1.可以使用tochar解决,数据集用selecttochar(flowdate,"yyyyMMddHH:mm:ss")fromtablename2.也可以把数据库日期类型date改成timestamp

java常用类(2)

三、时间处理相关类Date类:计算机世界把1970年1月1号定为基准时间,每个度量单位是毫秒(1秒的千分之一),用long类型的变量表示时间。Date分配Date对象并初始化对象,以表示自从标准基准时间(称为“历元”(epoch),即1970年1月1日08:00:00GMT)以来的指定毫秒数。示例:packagecn.tanjian

Java 日期时间

java.util包提供了Date类来封装当前的日期和时间。Date类提供两个构造函数来实例化Date对象。Date() 使用当前日期创建对象Date(longmillisec) 使用时间戳 即 从1970年1月1日开始的毫秒数。Date对象创建以后,可以调用下面的方法。1.booleanafter(Datedate)

HIVE 时间操作函数

日期函数UNIX时间戳转日期函数: from\_unixtime语法:   from\_unixtime(bigint unixtime\, string format\)返回值: string说明: 转化UNIX时间戳(从19700101 00:00:00 UTC到指定时间的秒数)到当前时区的时间格式举例:hive   selec