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 2007

Tip: Looking for answers? Try searching our database.

date in format yy-mm-dd hh:mm

Thread view: 
Sigi - 26 Jan 2007 17:42 GMT
Hi,
I have a Date object, and I need to obtain it in a human readable format.
If I use date.toString(), it gives:
     Fri Jan 26 17:47:57 CET 2007

What can I do to obtain it in the
     07-01-26 17:47
format?

Thanks.
www - 26 Jan 2007 17:58 GMT
> Hi,
> I have a Date object, and I need to obtain it in a human readable format.
[quoted text clipped - 6 lines]
>
> Thanks.

My program does this everyday. What I did was:

    String timeString  = null;
   
    SimpleDateFormat utc = new SimpleDateFormat("yy-MM-dd hh:mm"); //this
is the trick. You can set it "yyyy-MM-dd hh:mm:ss". y and Y means
different, and M & m, d &D, check Java API.
    utc.setTimeZone(TimeZone.getTimeZone("UTC")); //set time zone
    timeString = utc.format("your Date obj");
Lew - 26 Jan 2007 18:13 GMT
Sigi wrote:
>> I have a Date object, and I need to obtain it in a human readable format.
>> If I use date.toString(), it gives:
[quoted text clipped - 3 lines]
>>       07-01-26 17:47
>> format?

This is a very non-standard date format. Why choose this particular one?

N.b., whether a format is standard really only matters if you are sharing
results with others, but I am curious nonetheless.

- Lew
Mark Rafn - 26 Jan 2007 21:06 GMT
>Sigi wrote:
>>> What can I do to obtain it in the  07-01-26 17:47  format?

>This is a very non-standard date format. Why choose this particular one?

If it were 2007-01-26 17:47 it would be a fairly common format for
timestamping log entries.  It has a very large advantage over other standards
in that that it's ascii-sortable so it is trivial to merge log records and
preserve temporal sequence (assuming you're using UTC as your timezone;
daylight savings can mess this up otherwise).  

Dropping the century makes it suck, though, because it's then gets
confusing whether you're using this format, or the common US/Euro
shorhand m-d-y and d-m-y.  
--
Mark Rafn    dagon@dagon.net    <http://www.dagon.net/>
Lew - 26 Jan 2007 23:02 GMT
Sigi wrote:
>> What can I do to obtain it in the  07-01-26 17:47  format?

> If it were 2007-01-26 17:47 it would be a fairly common format for

<http://en.wikipedia.org/wiki/ISO_Date_Format>

Use of the space character ' ' in lieu of the 'T' between the date and time is
widely accepted for practical use.

> Dropping the century makes it suck, though, because it's then gets
> confusing whether you're using this format, or the common US/Euro
> shorhand m-d-y and d-m-y.  

or if so, which one:

07-01-26 =>
  July 1, ??26 vs. 7 January, ??26.

Except that these formats really use '/' not '-'.

- Lew
Thomas Fritsch - 26 Jan 2007 18:29 GMT
> I have a Date object, and I need to obtain it in a human readable format.
> If I use date.toString(), it gives:
[quoted text clipped - 3 lines]
>       07-01-26 17:47
> format?
  DateFormat dateFormat = new SimpleDateFormat("yy-MM-DD HH:mm");
    // You'll find more info about the pattern strings
    // in the API doc of SimpleDateFormat

  Date date = ...;
  String s = dateFormat.format(date);

Signature

Thomas



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



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