Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

dgasull

« Newer Snippets
Older Snippets »
Showing 1-3 of 3 total  RSS 

How to get a String with just the date from a Calendar

// Given Calendar cal

String date = cal.get(Calendar.DAY_OF_MONTH) + "-" 
    + cal.get(Calendar.MONTH) + "-" + cal.get(Calendar.YEAR);

How to add days to a date

// You should use the class Calendar.

// Given Calendar cal and int n with the number of days
cal.add(Calendar.DATE, n);

How to convert a String with a date to a Calendar

SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
Date date = sdf.parse(strDate);
Calendar cal = Calendar.getInstance();
cal.setTime(date);
« Newer Snippets
Older Snippets »
Showing 1-3 of 3 total  RSS