String.format()获取时间字符串

看核心一时,感觉String.format( )方法对获取时间相对简易,缺点是只能获取字符串,所以做个记录。

主要需要注意的是格式,Locale参数可以选择各个国家不同格式

		String.format("%tc", new Date()) ----- 完整时间 	:星期四 四月 25 22:53:47 CST 2019
		String.format("%tF", new Date()) ----- 年月日	  	:2019-04-25
		String.format("%tD", new Date()) ----- 月日年 	  	:04/25/19
		String.format("%tT", new Date()) ----- 24小时制	:22:53:47
		String.format("%tr", new Date()) ----- 12小时制	:10:53:47 下午 (添加Locale.ENGLISH参数,上下午是am/pm)
		String.format("%tR", new Date()) ----- 24小时没有秒 :22:53
		String.format("%tC", new Date()) ----- 年份前两位(补0)	:20
		String.format("%ty", new Date()) ----- 年份后两位(补0)	:19
		String.format("%tY", new Date()) ----- 年份		:2019
		String.format("%tB", new Date()) ----- 中文月份	:四月(添加Locale.JAPAN参数,显示的是 4月)
		String.format(Locale.ENGLISH, "%tB", new Date()) ----- 英文月份	:April
		String.format(Locale.ENGLISH, "%tb", new Date()) ----- 英文月份缩写   :Apr
		String.format("%tm", new Date()) ----- 数字月份(补0):04
		String.format("%td", new Date()) ----- 数字日期(补0):25
		String.format("%te", new Date()) ----- 数字日期(不补0):25
		String.format("%tA", new Date()) ----- 中文星期	:星期四
		String.format(Locale.ENGLISH, "%tA", new Date()) ----- 英文星期	:Thursday
		String.format(Locale.ENGLISH, "%ta", new Date()) ----- 英文星期缩写	:Thu
		String.format("%tH", new Date()) ----- 24制小时(补0):22
		String.format("%tk", new Date()) ----- 24制小时(不补0):22
		String.format("%tI", new Date()) ----- 12制小时(补0):10
		String.format("%tl", new Date()) ----- 12制小时(补0):10
		String.format("%tM", new Date()) ----- 分钟(补0)	:53
		String.format("%tS", new Date()) ----- 秒钟(补0)	:47
		String.format("%tp", new Date()) ----- 上下午标志 	:下午(添加Locale.ENGLISH参数,上下午是am/pm)
		String.format("%tZ", new Date()) ----- 时区		:CST
  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值