• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Example of convert String to Date

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all

i have some Problem covert String to Date i am sending My code also.

Date currentDatetime = new Date(System.currentTimeMillis());
SimpleDateFormat formatter1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss aaa");
String myDate = formatter1.format(currentDatetime);
System.out.println(myDate);
Date ss =formatter1.parse(myDate);
System.out.println(ss);

O/p: 2006-09-04 11:41:07 AM
Mon Sep 04 11:41:07 GMT+05:30 2006 (I want same Format in Date Type also yyyy-MM-dd HH:mm:ss aaa");

Thanks&Regards
Vinay
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You've got to use a formatter as in your first output, to get the desired format. Calling print on a Date instance will call Date.toString(), which uses "dow mon dd hh:mm:ss zzz yyyy" as the output format.
 
reply
    Bookmark Topic Watch Topic
  • New Topic