January 2 2017

Java calendar day_of_month

Java calendar day_of_month

Set the Calendar object to the date for which you need the calendar day of month, Calendar .get(Calendar. DAY_OF_MONTH) will give you day of the month. The first day of the month has value 1.

Example

package com.answersz;
 
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
 
public class JavaCalendarDayOfMonth {
 
public static void main(String[] args) throws ParseException {
 
// java calendar day_of_month
 
String date = "02-01-2017";
 
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
Date dt = sdf.parse(date);
 
Calendar cal = Calendar.getInstance();
cal.setTime(dt);
 
int dayOfMonth = cal.get(Calendar.DAY_OF_MONTH);
 
System.out.println("Date : " + dt);
System.out.println("Calendar day of month : " + dayOfMonth);
 
}
}

Output

Date : Mon Jan 02 00:00:00 IST 2017
Calendar day of month : 2


Copyright © 2014. All rights reserved.

Posted January 2, 2017 by answersz in category Core Java

Leave a Comment

Your email address will not be published. Required fields are marked *

*