Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SimpleDateFormat() help....

Status
Not open for further replies.

Exie

Programmer
Sep 3, 2003
156
AU
Hi Folks,

I'm trying to genrate a date string like so:
[Time].[All Times].[FY2009].[Q2].[OCT].[10]

... so I'm trying to use the simple date formatter like so:
String formatter = new SimpleDateFormat("'[Time].[All Times].[FY'yyyy'].[Q1].['MMM'].['dd']'").format(new Date());

Here's my problem:
1. How can I calculate the quarter ? eg Q1 - Q4
2. How can I get FY2009 ? for OCT2008 ?
3. How can I get the month MMM to come out in all uppercase ?
 
Code:
	{
		Date d = new Date ();
		String form1 = new SimpleDateFormat ("'[Time].[All Times].[FY'yyyy'].[#1][#2]['dd]").format (d);
		String mm    = new SimpleDateFormat ("M").format (d);
		int month = Integer.parseInt (mm);
		String q = "Q" + ((month+3)/4) + "]"; 
		String Mmm = new SimpleDateFormat ("MMM").format (d);
		String MMM = Mmm.toUpperCase ();
		System.out.println (form1.replaceAll ("#1", q).replaceAll ("#2", MMM));
	}
divide et impera.

don't visit my homepage:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top