cancel
Showing results for 
Search instead for 
Did you mean: 

format SimpleDateFormat

Former Member
0 Kudos

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

Accepted Solutions (0)

Answers (4)

Answers (4)

former_member751941
Active Contributor
0 Kudos

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

Former Member
0 Kudos

Hi,Mithu

Very helpfull answer.I solved my problem by myself,but

it was the problem with data types.

Regards,

Michael

former_member751941
Active Contributor
0 Kudos

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

Former Member
0 Kudos

It is still not working...

Any ideas?

Regards,

Michael

Former Member
0 Kudos

Hi Michael,

What exactly is your problem ? Is it that , in the dates you use , the time value is defaulted to something and not storing the exact value ? Can u re phrase the question.. with all details..

Regards

Bharathwaj

Former Member
0 Kudos

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

former_member182374
Active Contributor
0 Kudos

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

Former Member
0 Kudos

Hi,Omri

Yes,it is working fine with Calendar and I give the current date

and time,but is not working with my dates...

In my table I see it in right form.

What may be the problem?

Regards,

Michael

former_member1
Active Participant
0 Kudos

Hi Micheal,

Try HH:MM:SS instead of hh:mm:ss...

I hope it will work.

Thanks,

Anish

Former Member
0 Kudos

Hi,Anish

No,it is not working...

Any ideas?

Regards,

Michael

Former Member
0 Kudos

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

Former Member
0 Kudos

Hi,Bala

It is still not working...

In case of HH:mm I give 00:00

In case of hh:mm I give 12:00

In my table from where I give data,the date field is

of type "smalldatetime".

Any ideas?

Regards,

Michael