-1

我希望 2012 年 1 月 1 日将日历对象中的长值作为开始时间如何得到这个,我正在做如下

   Calendar today = Calendar.getInstance();
        today.set(Calendar.MILLISECOND, 0);
        today.set(Calendar.SECOND, 0);
        today.set(Calendar.MINUTE, 0);
        today.set(Calendar.HOUR, 0);
        long startTime = today.getTime().getTime();
4

2 回答 2

1

尝试这个:

Calendar firstOfYear = Calendar.getInstance();
firstOfYear.clear();
firstOfYear.set(Calendar.YEAR, 2012);
firstOfYear.set(Calendar.DAY_OF_YEAR,1); //first day of the year.
于 2012-04-27T11:08:49.713 回答
1
this is the another way

String str_date="01-JAN-2012";
DateFormat formatter ; 
Date date ; 
formatter = new SimpleDateFormat("dd-MMM-yyyy");
date = (Date)formatter.parse(str_date); 
Calendar cal=Calendar.getInstance();
cal.setTime(date);
System.out.println("=======>"+cal.getTimeInMillis());
于 2012-04-27T11:28:32.473 回答