版权声明
1. 本站文章和资源均来自互联网收集和整理,本站不承担任何责任及版权问题。
2. 相关版权归作者及其公司所有,仅供学习研究用途,请勿用于商业目的。
3. 若侵犯您的版权,请发邮件至webmaster@ishare1.cn联系我们,我们确认后将立即删除。

java把日期格式化:
import java.text.SimpleDateFormat;
import java.util.Date;
public class test{
public static void main(String args[]) {
Date newTime = new Date();
//设置时间格式
SimpleDateFormat sdf1 = new SimpleDateFormat("y-M-d h:m:s a E");
SimpleDateFormat sdf2 = new SimpleDateFormat("yy-MM-dd hh:mm:ss a E");
SimpleDateFormat sdf3 = new SimpleDateFormat("yyyy-MMM-ddd hhh:mmm:sss a E");
SimpleDateFormat sdf4 = new SimpleDateFormat("yyyyy-MMMM-dddd hhhh:mmmm:ssss a E");
//获取的时间,是本机的时间
String formatDate1 = sdf1.format(newTime);
String formatDate2 = sdf2.format(newTime);
String formatDate3 = sdf3.format(newTime);
String formatDate4 = sdf4.format(newTime);
System.out.println(formatDate1);
System.out.println(formatDate2);
System.out.println(formatDate3);
System.out.println(formatDate4);
}
}
输出结果如下:

java中使用SimpleDateFormat类的构造函数SimpleDateFormat(String str)构造格式化日期的格式,
通过format(Date date)方法将指定的日期对象格式化为指定格式的字符串.
更多java知识请关注java基础教程。
1、数组操作中,可以使用等于(=)赋值 注意:此时新数组只是指向原数组的存储空间,并没有重新申请新的空间。 实例: public class ArrayTest{ public static void main(String args[]){ // 1 int…
爱分享




