Dates formats

HiHow can I genertae a "regular" date format?i.e: 5.5.2001System.out.println( new java.util.Date().toString() );gives me a long format...
[179 byte] By [chenS] at [2007-9-26 4:36:28]
# 1

Hi !

Use the DateFormat class...

For example:

DateFormat m_dateFormat = DateFormat.getDateInstance(DateFormat.SHORT);

or

DateFormat m_dateFormat = DateFormat.getDateInstance(DateFormat.SHORT, Locale);

and provide a Locale to specify the formatting.

then just

String m_date = m_dateFormat.format(new Date());

Something like that...

Hope it helps.

qdasson at 2007-6-29 17:54:29 > top of Java-index,Archived Forums,Java Programming...
# 2
ok.thx.
chenS at 2007-6-29 17:54:29 > top of Java-index,Archived Forums,Java Programming...
# 3
you can use java.text.SimpleDateFormat to set your own format :SimpleDateFormat m_dateFormat = new SimpleDateFormat("dd.MM.yyyy");System.out.println(m_dateFormat.format(new Date()));
angifredf at 2007-6-29 17:54:29 > top of Java-index,Archived Forums,Java Programming...
# 4
And if I want to return a Time Object to SQL Server?(not String...)?
chenS at 2007-6-29 17:54:29 > top of Java-index,Archived Forums,Java Programming...
# 5
If you have a string on the form hh:mm:ss you can useTime m_time = Time.valueOf(m_string);Otherwise use the Date objectTime m_time = new Time(m_date.getTime());Something like that...
qdasson at 2007-6-29 17:54:29 > top of Java-index,Archived Forums,Java Programming...
# 6

What's not right on this:

SimpleDateFormat timeFormat = new SimpleDateFormat("H:mm:ss");

String s=timeFormat.format(new Date());

Time m_time = Time.valueOf(s);

return m_time;

The result column on the SQL Server is :

01/01/1900 17:13:53

I want only the time.

chenS at 2007-6-29 17:54:29 > top of Java-index,Archived Forums,Java Programming...
# 7

What does it print out if you add

SimpleDateFormat timeFormat = new SimpleDateFormat("H:mm:ss");

String s=timeFormat.format(new Date());

System.out.println(s);

Time m_time = Time.valueOf(s);

System.out.println(m_time);

Just the time or the date too...

qdasson at 2007-6-29 17:54:29 > top of Java-index,Archived Forums,Java Programming...
# 8
Strange..Just the time.(both of them)So why does the SQL takes the 1.1.1900 with it?
chenS at 2007-6-29 17:54:29 > top of Java-index,Archived Forums,Java Programming...
# 9
How is the column defined in the SQL db.Is it a time, date or something else...
qdasson at 2007-6-29 17:54:29 > top of Java-index,Archived Forums,Java Programming...
# 10
Just datetime column.
chenS at 2007-6-29 17:54:29 > top of Java-index,Archived Forums,Java Programming...
# 11
> Just datetime column.I believe that since the column is datetime it will always have a date component. Since you are setting it with a date that essentially is 0 it will give you 1900-01-01. I don't think this has to do with the Time object. It's in the database.
dubwai at 2007-6-29 17:54:29 > top of Java-index,Archived Forums,Java Programming...
# 12
Then the problem is in the db.Can't you change that to just a Time column...
qdasson at 2007-6-29 17:54:29 > top of Java-index,Archived Forums,Java Programming...
# 13
OK. I'll dig a little bit at the SQL Server about the datetime parameter.tank u all!
chenS at 2007-6-29 17:54:29 > top of Java-index,Archived Forums,Java Programming...