Calendar cal = Calendar.getInstance();
cal.set(Calendar.DAY_OF_MONTH, 1);
std = DateFormatUtil.nowDate(cal.getTime());
edd = DateFormatUtil.nowDate(new Date());DateFormatUtil是自己写的一个工具类
nowDate部分
public static String nowDate(Date date){
SimpleDateFormat nowFormat = new SimpleDateFormat("yyyy-MM-dd");
String now = nowFormat.format(date);
return now;}
还有个小问题,传回一个new Date()能得到当前时间?
cal.set(Calendar.DAY_OF_MONTH, 1);
std = DateFormatUtil.nowDate(cal.getTime());
edd = DateFormatUtil.nowDate(new Date());DateFormatUtil是自己写的一个工具类
nowDate部分
public static String nowDate(Date date){
SimpleDateFormat nowFormat = new SimpleDateFormat("yyyy-MM-dd");
String now = nowFormat.format(date);
return now;}
还有个小问题,传回一个new Date()能得到当前时间?
对
你试试
Date d=new Date();
然后打印一下
SimpleDateFormat nowFormat = new SimpleDateFormat("yyyy-MM-dd");
String now = nowFormat.format(date);
这句作用是转化成String类型从而适合你返回类型
String str = sdf.format(new Date());
System.out.println("当前时间是:"+str);
public void set(int field,
int value)将给定的日历字段设置为给定值。不管处于何种宽松性模式下,该值都不由此方法进行解释。 参数:
field - 给定的日历字段。
value - 给定日历字段所要设置的值。
比如2008/08/08 如果想知道现在是几几年或者几几月,可以用这个函数*/
Calendar cal = Calendar.getInstance(); //getInstance取得一个一个Calendar的实例
cal.set(Calendar.DAY_OF_MONTH, 1);//set方法设置日历字段值,即设为当前月1日
std = DateFormatUtil.nowDate(cal.getTime());
//cal.getTime()返回一个表示此 Calendar 时间值(从历元至现在的毫秒偏移量)的 Date 对象。
edd = DateFormatUtil.nowDate(new Date()); //new Date()获得系统的当前时间的一个实例/*std是对比如18000毫秒进行格式化输出为时/分/秒*/
/*edd是对比如获得的当前时间进行格式化输出*/
DateFormatUtil是自己写的一个工具类
nowDate部分
public static String nowDate(Date date){
SimpleDateFormat nowFormat = new SimpleDateFormat("yyyy-MM-dd"); //建立日期输出格式控制对象
String now = nowFormat.format(date); 传入参数date用format函数进行格式化
return now; //nowDate方法返回的值
//nowDate实现的功能就是对时间进行格式化yyyy-MM-dd,然后返回
} 希望达人指点一下