on 05-29-2007 8:15 AM
Hi,all
I have a problem with formatting date with SimpleDateFormat.
I need that the date will be of format dd/mm/yyyy hh:mm:ss
With date all is showing fine,I use dd/MM/yyyy ,but if I add
hh:mm:ss instead of right time I give 12:00:00.
What may be the problem?
Regards,
Michael
Message was edited by:
Michael Beilin
Hi Michael,
Check the data type of your input attribute whether it is "timestamp" or not
if it is "date" it will not give the time proper format. Make the input attribute type timestamp that you bind in the input field.
Regards,
Mithu
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Michael,
See this code to dipplay the date input field value.
Put the format you need.
Package
-
import java.sql.Date;
import java.text.ParseException;
import java.text.SimpleDateFormat;
Code:-
-
SimpleDateFormat smpdtFormat =new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
String validFr="";
validFr = wdContext.nodeProductDate().getElementAt(0).getAttributeValue("Validfr").toString();
prodElem.setValidFrom(new Date(smpdtFormat.parse(validFr).getTime()));
Regards,
Mithu
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,Bharathwaj
You are right,in the dates I give from my DB the time value is defaulted
to something (12:00:00) and not storing the exact value.
The date field in DB is of smalldatetime type and the dates in the table
are storing in right form (for example 12/04/2007 14:22:12).
But when I define SimpleDateFormat to "dd/MM/yyyy hh:mm:ss"
and doing format for date which I give from DB I see for example
the following:
12/04/2007 12:00:00
22/05/2007 12:00:00
and so on
What may be the problem?
Regards,
Michael
Try the following code:
Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss");
wdComponentAPI.getMessageManager().reportSuccess()(sdf.format(cal.getTime()).toString());
You should see something like: 29/05/2007 09:37:48
Omri
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Micheal,
Try HH:MM:SS instead of hh:mm:ss...
I hope it will work.
Thanks,
Anish
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Michael,
Use "HH:mm" for 0-23 hours and hh:mm" for 0-12 hours. For more details, refer http://java.sun.com/j2se/1.4.2/docs/api/java/text/SimpleDateFormat.html
Bala
User | Count |
---|---|
86 | |
10 | |
10 | |
9 | |
6 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.