Java工具类DateFormatUtils详解
日期和时间格式化实用程序和常量
public static String format(Calendar calendar, String pattern)
说明:将日历格式化为特定的模式;
参数:calendar-格式化的日历对象,非null;pattern-用于格式化日历的模式,非null;
返回值:格式化日历;
1
2
3
Calendar cal = Calendar.getInstance();
System.out.println(DateFormatUtils.format(cal, "yyyy-MM-dd HH:mm:ss"));
输出结果:2018-01-23 19:50:55
1
2
3
4
5
public static String format(Calendar calendar, String pattern,TimeZone timeZone)
说明:将日历格式化为特定的模式;
参数:calendar-格式化的日历对象,非null;pattern-用于格式化日历的模式,非null;timeZone-时区
返回值:格式化日历;
1
2
3
Calendar cal = Calendar.getInstance();
System.out.println(DateFormatUtils.format(cal, "yyyy-MM-dd HH:mm:ss", TimeZone.getDefault()));
1
2
public static String format(Calendar calendar, String pattern, Locale locale)
说明:将日历格式化为特定的模式;
参数:calendar-格式化的日历对象,非null;pattern-用于格式化日历的模式,非null;locale-本地化
返回值:格式化日历;
1
2
3
Calendar cal = Calendar.getInstance();
System.out.println(DateFormatUtils.format(cal, "yyyy-MM-dd HH:mm:ss", Locale.CHINA));
1
2
public static String format(Calendar calendar,String pattern,TimeZone timeZone,Locale locale)
说明:格式化日期时指定时区和本地化参数;
1
public static String format(Date date, String pattern)
说明:将日期格式化为特定的模式;
参数:date-格式化的日期对象,非null;pattern-用于格式化日期的模式,非null;
返回值:格式化日期;
1
2
3
Date date = new Date();
System.out.println(DateFormatUtils.format(date, "yyyy-MM-dd HH:mm:ss"));
1
2
public static String format(Date date,String pattern,TimeZone timeZone)
说明:将日期格式化为特定的模式;
参数:date-格式化的日期对象,非null;pattern-用于格式化日期的模式,非null;timeZone-时区
返回值:格式化日期;
1
2
3
Date date = new Date();
System.out.println(DateFormatUtils.format(date, "yyyy-MM-dd HH:mm:ss", TimeZone.getDefault()));
1
2
public static String format(Date date, String pattern, Locale locale)
说明:将日期格式化为特定的模式;
参数:date-格式化的日期对象,非null;pattern-用于格式化日期的模式,非null;locale-本地化参数
返回值:格式化日期;
1
2
3
public static String format(Calendar calendar,String pattern,TimeZone timeZone,Locale locale)
说明:格式化日期时指定时区和本地化参数;
1
public static String format(long millis,String pattern)
说明:将日期/时间格式化为特定的模式;
参数:mills-以毫秒表示格式的日期;pattern-格式化的模式;
1
2
public static String formatUTC(Date date,String pattern)
说明:使用UTC时区将日期/时间格式化为特定的模式;
参数:date-要格式化的时间;pattern-格式化的模式;
返回值:格式化的日期;
---------------------
作者:随风yy
来源:CSDN
原文:https://blog.csdn.net/yaomingyang/article/details/79143954
版权声明:本文为博主原创文章,转载请附上博文链接!
最新文章
- python操作mysql总结
- A little bit about Handlers in JAX-WS
- Maya 脚本控制物体自转
- Gson将参数放入实体类中进行包装之后再传递
- Larave 多图片上传
- C++多态性与C#的比较
- Dreamweaver 添加 cakephp ctp后缀名
- python调用smtplib模块发送邮件
- Sqlserver 正则替换函数的一种实现
- ASP.NET MVC 4.0的Action Filter
- Houdini Pyro流体的插值变速
- java的property
- js中的字符替换
- js with用法
- SQL根据B表内容修改A表内容,查询表中重复记录,删除掉重复项只保留一条
- .NET领域最为流行的IOC框架之一Autofac WebAPI2使用Autofac实现IOC属性注入完美解决方案 AutoFac容器初步
- RLE Plots: relative log expression
- mvc core2.1 Identity.EntityFramework Core 登录 (三)
- WebFlux基础之响应式编程
- 安卓开发笔记——TabHost组件(一)(实现底部菜单导航)