java 格式化日期时间_JAVA格式化时间日期方法介绍「建议收藏」

JAVA格式化时间日期importjava.util.Date;importjava.text.DateFormat;http://www.guiyang365.com//***格式化时间类*DateFormat.FULL=0*DateFormat.DEFAULT=2*DateFormat.LONG=1*DateFormat.MEDIUM=2*DateFormat….

大家好,又见面了,我是你们的朋友全栈君。

JAVA格式化时间日期

import java.util.Date;

import java.text.DateFormat;http://www.guiyang365.com/

/**

* 格式化时间类

* DateFormat.FULL = 0

* DateFormat.DEFAULT = 2

* DateFormat.LONG = 1

* DateFormat.MEDIUM = 2

* DateFormat.SHORT = 3

* @author    Michaelhttp://www.guiyang365.com/

* @version   1.0, 2007/03/09

*/

public class Test{

public static void main(String []args){

Date d = new Date();http://www.guiyang365.com/

String s;

/** Date类的格式: Sat Apr 16 13:17:29 CST 2006 */

System.out.println(d);

System.out.println(“******************************************”);

/** getDateInstance() */

/** 输出格式: 2006-4-16 */

s = DateFormat.getDateInstance().format(d);

System.out.println(s);

/** 输出格式: 2006-4-16 */

s = DateFormat.getDateInstance(DateFormat.DEFAULT).format(d);

System.out.println(s);

/** 输出格式: 2006年4月16日 星期六 */

s = DateFormat.getDateInstance(DateFormat.FULL).format(d);

System.out.println(s);

/** 输出格式: 2006-4-16 */

s = DateFormat.getDateInstance(DateFormat.MEDIUM).format(d);

System.out.println(s);

/** 输出格式: 06-4-16 */

s = DateFormat.getDateInstance(DateFormat.SHORT).format(d);

System.out.println(s);

/** 输出格式: 2006-01-01 00:00:00 */

java.text.DateFormat format1 = new java.text.SimpleDateFormat(“yyyy-MM-dd hh:mm:ss”);

s = format1.format(new Date());

System.out.println(s);

/** 输出格式: 2006-01-01 00:00:00 */

System.out.println((new java.text.SimpleDateFormat(“yyyy-MM-dd hh:mm:ss”)).format(new Date()));

/** 输出格式: 20060101000000***/https://wangzepeng.cn/

java.text.DateFormat format2 = new java.text.SimpleDateFormat(“yyyyMMddhhmmss”);

s = format2.format(new Date());https://wangzepeng.cn/

System.out.println(s);https://wangzepeng.cn/

}

}

标签:java,格式化,DateFormat,format,System,日期,println,JAVA,out

来源: https://www.cnblogs.com/javaahb/p/12923143.html

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/127285.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号