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()能得到当前时间?

解决方案 »

  1.   

    还有个小问题,传回一个new Date()能得到当前时间?

    你试试
    Date d=new Date();
    然后打印一下
    SimpleDateFormat nowFormat = new SimpleDateFormat("yyyy-MM-dd"); 
    String now = nowFormat.format(date); 
    这句作用是转化成String类型从而适合你返回类型
      

  2.   

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd HH:mm:ss");
    String str = sdf.format(new Date());
    System.out.println("当前时间是:"+str);
      

  3.   

    其实主要还是想问一下Calendar 这个在这上面的应用不过非常感谢一楼和三楼!也会给你们分分的哟!
      

  4.   

    可以参考API:Calendar 类是一个抽象类,它为特定瞬间与一组诸如 YEAR、MONTH、DAY_OF_MONTH、HOUR 等 日历字段之间的转换提供了一些方法,并为操作日历字段(例如获得下星期的日期)提供了一些方法。瞬间可用毫秒值来表示,它是距历元(即格林威治标准时间 1970 年 1 月 1 日的 00:00:00.000,格里高利历)的偏移量。
    public void set(int field,
                    int value)将给定的日历字段设置为给定值。不管处于何种宽松性模式下,该值都不由此方法进行解释。 参数:
    field - 给定的日历字段。
    value - 给定日历字段所要设置的值。 
      

  5.   

    /*Calendar 是一个抽象类,可以单独取得某个时间或日期信息,
    比如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,然后返回
    } 希望达人指点一下