I have date in this format 2011-11-02
. From this date, how can we know the Day-of-week
, Month
and Day-of-month
, like in this format Wednesday-Nov-02
, from calendar or any other way?
Two extract the value for Month, first note that we have to cut the first four digits off so that yyyymmdd becomes mmdd. Then, dividing mmdd by 100 yields mm. This is done with MOD(Number,10000)/100, where MOD(Number,10000) retrieves mmdd and this result is divided by 100 yielding Month.
First, pick the cells that contain dates, then right-click and select Format Cells. Select Custom in the Number Tab, then type 'dd-mmm-yyyy' in the Type text box, then click okay. It will format the dates you specify.
Select the cells you want to format. Press CTRL+1. In the Format Cells box, click the Number tab. In the Category list, click Date, and then choose a date format you want in Type.
If it were normal java, you would use two SimpleDateFormats - one to read and one to write:
SimpleDateFormat read = new SimpleDateFormat("yyyy-MM-dd");
SimpleDateFormat write = new SimpleDateFormat("EEEE-MMM-dd");
String str = write.format(read.parse("2011-11-02"));
System.out.println(str);
Output:
Wednesday-Nov-02
As a function (ie static method) it would look like:
public static String reformat(String source) throws ParseException {
SimpleDateFormat read = new SimpleDateFormat("yyyy-MM-dd");
SimpleDateFormat write = new SimpleDateFormat("EEEE-MMM-dd");
return write.format(read.parse(source));
}
Warning:
Do not be tempted to make read
or write
into static fields to save instantiating them every method invocation, because SimpleDateFormat is not thread safe!
However, after consulting the Blackberry Java 5.0 API doc, it seems the write.format
part should work with blackberry's SimpleDateFormat, but you'll need to parse the date using something else... HttpDateParser looks promising. I don't have that JDK installed, but try this:
public static String reformat(String source) {
SimpleDateFormat write = new SimpleDateFormat("EEEE-MMM-dd");
Date date = new Date(HttpDateParser.parse(source));
return write.format(date);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With