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!

how can i get month string from date string?

Status
Not open for further replies.

GoSooJJ

Programmer
Feb 24, 2001
76
US
hi all~
today i faced dateformat display.
anyone knows how to retrieve only 3 string month, such as Jan, Feb, Mar, Apr, so on...
If i have 2001-01-01 00:00:00 this date, how can I format this to display only month.
Thx all~

JJ //
 
If your date is stored as a java.util.Date object, then the easiest way I know of controlling its display is to use the SimpleDateFormat object:

import java.text.SimpleDateFormat;
...

SimpleDateFormat sdf = new SimpleDateFormat( "MMM" );
String strMonth = sdf.format( dDate );
...

If the dDate object is set as you've given above, then strMonth will contain "Jan". A full description of the format codes is given in the Java API Specification, package java.text, class SimpleDateFormat.

If your original date was stored in a string not a Date, then it can be converted into a Date using SimpleDateFormat.parse( strDate ) - using a different SimpleDateFormat object created with a different format string.
 
hi stephendfrancis,

Thank you so much. Before I couldn't use SimpleDateFormat, but your tip was very helpful. Now I got what I need.
Again, thx!!!

JJ //
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top