Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / January 2008

Tip: Looking for answers? Try searching our database.

how can i change the date format

Thread view: 
KelvinWongYW@gmail.com - 14 Jan 2008 03:50 GMT
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
Lew - 14 Jan 2008 04:19 GMT
> 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.

Signature

Lew

Andrew Thompson - 14 Jan 2008 05:07 GMT
On Jan 14, 2:50 pm, KelvinWon...@gmail.com 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.

--
Andrew T.
PhySci.org
Roedy Green - 14 Jan 2008 09:59 GMT
>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.

Signature

Roedy Green, Canadian Mind Products
The Java Glossary, http://mindprod.com

armwrestlingwithchasanddave@hotmail.com - 31 Jan 2008 00:52 GMT
On Jan 14, 9:59 am, Roedy Green <see_webs...@mindprod.com.invalid>
wrote:
> On Sun, 13 Jan 2008 19:50:48 -0800 (PST), KelvinWon...@gmail.com
> wrote, quoted or indirectly quoted someone who said :
[quoted text clipped - 18 lines]
> Roedy Green, Canadian Mind Products
> The Java Glossary,http://mindprod.com

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";
        }
    }
Roedy Green - 31 Jan 2008 10:37 GMT
On Wed, 30 Jan 2008 16:52:24 -0800 (PST),
armwrestlingwithchasanddave@hotmail.com wrote, quoted or indirectly
quoted someone who said :

>It's much better (and easier) to just do this:
>    private static String getSuffix(int i) {
[quoted text clipped - 13 lines]
>        }
>    }

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";
     }
  }

Signature

Roedy Green, Canadian Mind Products
The Java Glossary, http://mindprod.com



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.