Results 1 to 7 of 7

Thread: Using date format in JSP

  1. #1
    Join Date
    Sep 2009
    Posts
    143

    Using date format in JSP

    Hello,
    So I have a mysql database table with 3 fields in a date format. I then form into a JSP where I enter a promotion with the pre-named fields. Already one, is it possible to directly display the current date in the field that is TIME_STAMP so that the user does not change anything? Then it is possible to direct a field with the date format as pre-written |--/--/----|? And the question that bothers me most, how to convert String that receives my servlet to send date format in my database?

  2. #2
    Join Date
    Dec 2009
    Posts
    192

    Re: Using date format in JSP

    Hi,
    Try the following code

    Code:
    Promo test = new promo(),
    				/ / test.setIdPromo (Promos.listePromo (). size () +1);
    				test.setTitrePromo(request.getParameter("create")), 
    				test.setDescPromo(request.getParameter("remove")); 
    				test.setDatecreation(request.getParameter("datecreate")); 
    				test.setDatedebut(request.getParameter("request date"));
    				test.setDatefin(request.getParameter("date parameter"));

  3. #3
    Join Date
    Mar 2010
    Posts
    182

    Re: Using date format in JSP

    You have to create a Date object from your string passed in parameter with a SimpleDateFormat:
    Code:
    SimpleDateFormat test = new SimpleDateFormat("dd / MM / yyyy"); P.setDatecreation(test.parse(request.getParameter("create date")));
    I think this should work find for you.

  4. #4
    Join Date
    Dec 2009
    Posts
    192

    Re: Using date format in JSP

    I added this method:

    Code:
    public static Date stringToDate(dt String, String fmt) throws Exception (
            SimpleDateFormat test = new SimpleDateFormat(fmt);
            return test.parse(dt);
    )
    but already it gives me an error message as what it can not convert a date type to Date. I guess this is due to two date formats are java.util.date and java.sql.Date. In my case I think it java.sql.Date to be used.

  5. #5
    Join Date
    Nov 2009
    Posts
    518

    Re: Using date format in JSP

    You can alternatively try this

    Code:
    private java.sql.Date toSqlDate(final String dt) throws java.text.ParseException (
    SimpleDateFormat formatter = new SimpleDateFormat("dd / MM / yyyy"); frm.setLenient(false); java.util.Date = prsdt frm.parse(dt);
    return new java.sql.Date(prsdt.getTime());
    )

  6. #6
    Join Date
    Mar 2010
    Posts
    330

    Re: Using date format in JSP

    In a practical concern I decided to removed the timestamp. Suddenly I come to get my three dates but not a display he puts me an error:
    java.lang.NoSuchMethodError, my method
    Code:
    public Date getDatecreation() (
    	return DateCreated;
    )
    I guess it happens not to be displayed this variable format. Do I have to mail it a String or other?

  7. #7
    Join Date
    Mar 2010
    Posts
    197

    Re: Using date format in JSP

    Then I think you wild. You have removed the timestamp? It means that you changed debug the contents of your variable? Normal until it crashes ... But it is launched or NoSuchError? You talk in your date of getter, you really want a date sql or you took the first one came? That gives you System.out.println (getDateCreation (). ToString ())?

Similar Threads

  1. Problem in date format
    By Vodka in forum Software Development
    Replies: 5
    Last Post: 19-02-2010, 04:38 AM
  2. Insert date format in SQL via ASP
    By Bansi_WADIA in forum Software Development
    Replies: 4
    Last Post: 04-12-2009, 10:56 PM
  3. Changing Date format in Excel
    By Jamaima in forum Windows Software
    Replies: 3
    Last Post: 15-10-2009, 02:06 PM
  4. Changing the date format
    By Uzair in forum Customize Desktop
    Replies: 3
    Last Post: 03-04-2009, 12:44 PM
  5. whenCreated Date Format
    By settler in forum Active Directory
    Replies: 3
    Last Post: 04-01-2007, 08:44 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,711,725,063.15430 seconds with 16 queries