A friendly place for programming greenhorns!
Big Moose Saloon
Search
|
Java FAQ
|
Recent Topics
Register / Login
Win a copy of
Arduino in Action
this week in the
General Computing
forum!
A special promo:
Enter your blog post or vote on a blogger to be featured in an upcoming Journal
JavaRanch
»
Java Forums
»
Java
»
Beginning Java
Author
how to quickly get current year/month ?
Steve Mutanson
Ranch Hand
Joined: Apr 15, 2003
Posts: 67
posted
Jul 16, 2003 14:58:00
0
How to quickly get current year and month ? I guess there are different ways but can somebody show me an easy way ?
thanks,
Michael Dunn
Ranch Hand
Joined: Jun 09, 2003
Posts: 4632
posted
Jul 16, 2003 16:24:00
0
One of the ways
import java.util.*; class testing { public static void main(String args[]) { Calendar cal = Calendar.getInstance(); int year = cal.get(cal.YEAR); int month = cal.get(cal.MONTH)+1; //zero-based System.out.println("year = "+year+"\nmonth = "+month); System.exit(0); } }
Jamie Robertson
Ranch Hand
Joined: Jul 09, 2001
Posts: 1879
I like...
posted
Jul 17, 2003 12:20:00
0
if you just want a
String
representation of the current date, use the
SimpleDateFormat
class:
SimpleDateFormat formatter = new SimpleDateFormat( "yyyyMM" ); String today = formatter.format( new java.util.Date() );
Jamie
I agree. Here's the link:
http://zeroturnaround.com/jrebel
- it saves me about five hours per week
subject: how to quickly get current year/month ?
Similar Threads
Display current year and month
multi month calendar
date dateformat
Date
dateformat in textfield
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter