• Post Reply Bookmark Topic Watch Topic
  • New Topic

Get Month and Year from Calander  RSS feed

 
vivek dhiman
Ranch Hand
Posts: 155
Netbeans IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I have Georgian Calander object


It prints :

date :::: java.util.GregorianCalendar[time=1408045500000,areFieldsSet=true,
areAllFieldsSet=true,lenient=false,zone=sun.util.calendar.ZoneInfo[id="GMT+05:30",
offset=19800000,dstSavings=0,useDaylight=false,transitions=0,lastRule=null],
firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=2014,MONTH=7,
WEEK_OF_YEAR=33,WEEK_OF_MONTH=3,DAY_OF_MONTH=15,DAY_OF_YEAR=227,
DAY_OF_WEEK=6,DAY_OF_WEEK_IN_MONTH=3,AM_PM=0,HOUR=1,
HOUR_OF_DAY=1,MINUTE=15,SECOND=0,MILLISECOND=0,
ZONE_OFFSET=19800000,DST_OFFSET=0]


I want month and year from this like August 2014.

How can i do the same.

Thanks
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16059
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Call getTime() on the Calendar object; that will give you a java.util.Date object.

Then use a java.text.SimpleDateFormat object to format the Date object into a string with the desired format. See the API documentation of SimpleDateFormat, it explains how to specify the format you want.
 
Campbell Ritchie
Marshal
Posts: 56536
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try the %T tags which are described in the Java Tutorials and the Formatter class documentation.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!