#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    9
    Rep Power
    0

    Java String to date format help


    Hello friends,

    I want a help in typecasting a variable(in String) to date format without changing its format style(yy/mm/dd).
    I wrote these codes and my goal is to insert the formatted date to MySQL db.

    please help me ,
    The code is given below :

    Code:
    Date date = new Date();
    SimpleDateFormat sdf;
    sdf = new SimpleDateFormat("dd/MM/yyyy");
    String date_str=sdf.format(date);
    date=sdf.parse(date_str);
    If there is any other ways to insert date value to MySQL please update me(in yy/mm/dd format)

    Thanx for the help in advance !!
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    9
    Rep Power
    0
    In date_str variable, i am getting the format i want

    Code:
    29/05/2013
    But after parsing the style get changed and in the vaiable date , i am getting this kind of format

    Code:
    Wed May 29 00:00:00 IST 2013
    guys help , please !!
  4. #3
  5. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,724
    Rep Power
    348
    i am getting this kind of format
    Wed May 29 00:00:00 IST 2013
    What method are you using to format the String that you posted?
  6. #4
  7. No Profile Picture
    Permanently Banned
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    5
    Rep Power
    0

    Ans


    How it will be perform in c++
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    9
    Rep Power
    0
    @Norm :

    The code is in the question dude...
    By using that code i formatted the new Date().
  10. #6
  11. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,724
    Rep Power
    348
    Where is the statement that prints out the following:
    Wed May 29 00:00:00 IST 2013

    I don't see it in what is posted.
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    9
    Rep Power
    0
    @Norm :

    The variable "date" contains that output.
    I removed the printout statement before posting the code.
    The following code will O/P "Wed May 29 00:00:00 IST 2013" value.

    Code:
    System.out.println(date);
  14. #8
  15. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,724
    Rep Power
    348
    Code:
    System.out.println(date);
    In that code the Date class's toString() method formats the contents of the Date class object.
    If you want a different String from the contents of the Date object you will have to use a class/method to format it.
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    9
    Rep Power
    0
    Okey..
    thnx..
    I will try it !!


IMN logo majestic logo threadwatch logo seochat tools logo