The Amazing Android

Saturday, 11 July 2015

Today Date and Last day of Month

public class GetLastDayOfMonth {   
 
    public static void main(String[] args) {  
 
        Date today = new Date();  
 
        Calendar calendar = Calendar.getInstance();  
        calendar.setTime(today);  
 
        calendar.add(Calendar.MONTH, 1);  
        calendar.set(Calendar.DAY_OF_MONTH, 1);  
        calendar.add(Calendar.DATE, -1);  
 
        Date lastDayOfMonth = calendar.getTime();  
 
        DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");  
        System.out.println("Today            : " + sdf.format(today));  
        System.out.println("Last Day of Month: " + sdf.format(lastDayOfMonth));  
    }   
 
}  
Output:
Today            : 2010-08-03  
Last Day of Month: 2010-08-31 
Posted by Hitesh Prajapati at 06:35 No comments:
Email ThisBlogThis!Share to XShare to FacebookShare to Pinterest
Newer Posts Older Posts Home
Subscribe to: Posts (Atom)

About Me

Hitesh Prajapati
View my complete profile

Blog Archive

  • ▼  2015 (25)
    • ▼  October (1)
      • When click on child of Listitem of Listview then o...
    • ►  September (2)
    • ►  July (4)
    • ►  June (8)
    • ►  May (2)
    • ►  April (8)

Links

  • Android Tutorials
  • Android Application Projects & Development
All Rights reserved . Simple theme. Powered by Blogger.