Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > how can i change the date format

Reply
Thread Tools

how can i change the date format

 
 
KelvinWongYW@gmail.com
Guest
Posts: n/a
 
      01-14-2008
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
 
Reply With Quote
 
 
 
 
Lew
Guest
Posts: n/a
 
      01-14-2008
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> 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.

--
Lew
 
Reply With Quote
 
 
 
 
Andrew Thompson
Guest
Posts: n/a
 
      01-14-2008
On Jan 14, 2:50*pm, (E-Mail 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.

--
Andrew T.
PhySci.org
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      01-14-2008
On Sun, 13 Jan 2008 19:50:48 -0800 (PST), (E-Mail Removed)
wrote, quoted or indirectly quoted someone who said :

>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.

--
Roedy Green, Canadian Mind Products
The Java Glossary, http://mindprod.com
 
Reply With Quote
 
armwrestlingwithchasanddave@hotmail.com
Guest
Posts: n/a
 
      01-31-2008
On Jan 14, 9:59 am, Roedy Green <(E-Mail Removed)>
wrote:
> On Sun, 13 Jan 2008 19:50:48 -0800 (PST), (E-Mail Removed)
> wrote, quoted or indirectly quoted someone who said :
>
> >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 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.
>
> --
> 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";
}
}
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      01-31-2008
On Wed, 30 Jan 2008 16:52:24 -0800 (PST),
(E-Mail Removed) wrote, quoted or indirectly
quoted someone who said :

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

--
Roedy Green, Canadian Mind Products
The Java Glossary, http://mindprod.com
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Date#parse assume a EU format - can it assume a US format? Josh Sharpe Ruby 1 09-21-2010 09:16 AM
Re: How can I change Date format in DateChooser Lew Java 1 07-29-2009 03:50 PM
Date, date date date.... Peter Grison Java 10 05-30-2004 01:20 PM
Date Format - best way of converting a string into a date format Brian Candy ASP .Net 2 02-18-2004 02:13 PM



Advertisments