2015-06-14 210 views
-1

我怎样才能获得第一天的00:00和最后一天也是上个月的00:00(currentMonth -1)作为日期。 我在Sqlite中使用unix时间戳记的值,有没有简单的方法来过滤特定月份的值。例如,当前月份是六月份,我想要统计6月份有多少个值为unix时间戳(2014年6月,2013年6月...),而没有指定任何年份或日期。Android日历计数月份

我得到当前时间戳这样

Long timestamp = System.currentTimeMillis()/1000; 

回答

0
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); 
       Calendar cal = Calendar.getInstance(); 
       cal.add(Calendar.MONTH, -1);  
       String lastmonth = dateFormat.format(cal.getTime()); 
       Toast.makeText(getApplicationContext(), lastmonth, Toast.LENGTH_LONG).show(); 

我发现了如何获得最后一个月,但还是不知道如何获得特定月份的每年。