String date = new SimpleDateFormat("MM,dd,yyyy", Locale.SIMPLIFIED_CHINESE).format(new java.util.Date());
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd kk:mm:ss"); 注意在后面,输出的格式可以自己控制
刚学java,有些东西不太懂,请大家帮忙解决
package common;import java.text.SimpleDateFormat; import java.util.Date;/** * @author zhang_wj * */ public class DateControl { /* * 输出YYYY-MM-DD */ public static String getStringYearMonthDate(){ Date currentTime = new Date(); SimpleDateFormat formatter = new SimpleDateFormat ("yyyy-MM-dd"); String dateString = formatter.format(currentTime); return dateString; } public static void main(String[] args)throws Exception{
DateControl datecontorl = new DateControl(); System.out.println(datecontorl.getStringYearMonthDate()); } }
public class test { public static void main(String[] args) { SimpleDateFormat sdf=new SimpleDateFormat("yyyyMM"); String date = sdf.format(new Date()); System.out.println(date); } }
我没有看清,你要要求,不好意思。 public static String getStringYearMonthDate2(){ Date currentTime = new Date(); SimpleDateFormat formatter = new SimpleDateFormat ("yyyyMMdd"); String dateString = formatter.format(currentTime); return dateString; }
挑战技术,超越自我!!
或者
new Calendar()
Locale.SIMPLIFIED_CHINESE).format(new java.util.Date());
注意在后面,输出的格式可以自己控制
import java.util.Date;/**
* @author zhang_wj
*
*/
public class DateControl {
/*
* 输出YYYY-MM-DD
*/
public static String getStringYearMonthDate(){ Date currentTime = new Date();
SimpleDateFormat formatter = new SimpleDateFormat ("yyyy-MM-dd");
String dateString = formatter.format(currentTime);
return dateString; }
public static void main(String[] args)throws Exception{
DateControl datecontorl = new DateControl();
System.out.println(datecontorl.getStringYearMonthDate());
}
}
public class test {
public static void main(String[] args) {
SimpleDateFormat sdf=new SimpleDateFormat("yyyyMM");
String date = sdf.format(new Date());
System.out.println(date);
}
}
public static String getStringYearMonthDate2(){ Date currentTime = new Date();
SimpleDateFormat formatter = new SimpleDateFormat ("yyyyMMdd");
String dateString = formatter.format(currentTime);
return dateString; }