how can i change the date format

K

KelvinWongYW

Dear All,

i have some problem on changing the date format.

i would like to change 2008-02-15 to 15th which the th should be the
power of 15

is there any method to do it ? i am so familiar with JAVA and i have
look for the answer on web but cannot find

hope someone can help me out

thanks
 
L

Lew

i [sic] have some problem on changing the date format.

i would like to change 2008-02-15 to 15th which the th should be the
power of 15

What do you mean by "the th should be the power of 15"? That doesn't make any
kind of sense that I can discern.
is there any method to do it ? i am so familiar with JAVA

It's "Java", not "JAVA".
and i have look for the answer on web but cannot find

hope someone can help me out

<http://java.sun.com/javase/6/docs/api/java/text/DateFormat.html>

Always start with the Javadocs if you have a Java API matter.
 
A

Andrew Thompson

On Jan 14, 2:50 pm, (e-mail address removed) wrote:
...
i would like to change 2008-02-15 to 15th which the th should be the
power of 15

Did you mean that the 'th' characters should be
written as a superscript (raised above the normal
baseline of the text flow)?

e.g.
<sscce>
import javax.swing.*;

class SuperScript {

public static void main(String[] args) {
String html =
"<html><body>" +
"<p>2<sup>3</sup> = 2 x 2 x 2";
JOptionPane.showMessageDialog(
null,
new JLabel(html) );
}
}
</sscce>

Also: note that in English, the word 'I' should
*always* be capitalized.
 
R

Roedy Green

i would like to change 2008-02-15 to 15th which the th should be the
power of 15

In North America that form disappeared back in the 50s, so I don't it
occurred to the Sun people to support it directly. What you can do is
this:

Display the date normally. Extract the day of the month. Use my
ordinalSuffix method to tack on a suffix.

See the code for ordinalSuffix at
http://mindprod.com/jgloss/ordinal.html

For applying ordinal suffixes to arbitrarily large numbers written out
in words see http://mindprod.com/products1.html#INWORDS
look at the AmericanOrdinals class.
 
A

armwrestlingwithchasanddave

In North America that form disappeared back in the 50s, so I don't it
occurred to the Sun people to support it directly. What you can do is
this:

Display the date normally. Extract the day of the month. Use my
ordinalSuffix method to tack on a suffix.

See the code for ordinalSuffix athttp://mindprod.com/jgloss/ordinal.html

For applying ordinal suffixes to arbitrarily large numbers written out
in words seehttp://mindprod.com/products1.html#INWORDS
look at the AmericanOrdinals class.

Interesting, I've never heard of the 11st, 12nd or 13rd...

It's much better (and easier) to just do this:
private static String getSuffix(int i) {
switch (i) {
case 1:
case 21:
case 31:
return "st";
case 2:
case 22:
return "nd";
case 3:
case 23:
return "rd";
default:
return "th";
}
}
 
R

Roedy Green

It's much better (and easier) to just do this:
private static String getSuffix(int i) {
switch (i) {
case 1:
case 21:
case 31:
return "st";
case 2:
case 22:
return "nd";
case 3:
case 23:
return "rd";
default:
return "th";
}
}

here is my corrected version

/**
* produces an ordinal "th" suffix string for given number.
* @param number value you want the ordinal suffix for:
* @return corresponding ordinal suffix, i.e. "st", "nd", "rd", or
"th"
*/
String ordinalSuffix ( int value )
{
value = Math.abs( value );
final int lastDigit = value % 10;
final int last2Digits = value % 100;
switch ( lastDigit )
{
case 1 :
return last2digits == 11 ? "th" : "st";

case 2:
return last2digits == 12 ? "th" : "nd";

case 3:
return last2digits == 13 ? "th" : "rd";

default:
return "th";
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top