Skip to Content
author's profile photo Former Member
Former Member

format SimpleDateFormat

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

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

4 Answers

  • Posted on May 29, 2007 at 07:40 AM

    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

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      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

  • author's profile photo Former Member
    Former Member
    Posted on May 29, 2007 at 08:25 AM

    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

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      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

  • Posted on May 29, 2007 at 07:20 AM

    Hi Micheal,

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

    I hope it will work.

    Thanks,

    Anish

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on May 29, 2007 at 09:53 AM

    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

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.