Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Java in General
Search Coderanch
Advance search
Google search
Register / Login
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
Ron McLeod
Tim Cooke
Paul Clapham
Liutauras Vilda
Sheriffs:
Junilu Lacar
Rob Spoor
Jeanne Boyarsky
Saloon Keepers:
Stephan van Hulst
Carey Brown
Tim Holloway
Piet Souris
Bartenders:
Forum:
Java in General
Problem with date formatting
sahana mithra
Ranch Hand
Posts: 72
posted 11 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Dear all,
My system reboot time which is like 20111205105400.375199+330 must be formatted like 05/12/2011 10:54:00 AM IST.
Here is what i have tried
newrebootTime = rebootTime.substring(0, rebootTime.indexOf(".")); // this prints 20111205105400 final SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy h:mm:ss a z"); try{ Date d = sdf.parse(newrebootTime); System.out.println(d); }catch(Execption e)( System.out.println("error: " + e);; }
I get the following exception: error: java.text.ParseException: Unparseable date: "20111205105400"
Please help me to overcome this.
Thank you all.
John Jai
Rancher
Posts: 1776
posted 11 years ago
1
Number of slices to send:
Optional 'thank-you' note:
Send
You have to use one format to convert the input
String
to date and another to show the converted date as desired.
String inputDate = "20111205105400"; final SimpleDateFormat inputFormat = new SimpleDateFormat("yyyyMMddhhmmss"); final SimpleDateFormat outputFormat = new SimpleDateFormat("dd/MM/yyyy h:mm:ss a"); try{ Date d = inputFormat.parse(inputDate); System.out.println(outputFormat.format(d)); }catch(Exception e){ System.out.println("error: " + e); }
sahana mithra
Ranch Hand
Posts: 72
posted 11 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi Jai,
Thank you so much for the solution.
CLUCK LIKE A CHICKEN! Now look at this tiny ad:
The Low Tech Laboratory Movie Kickstarter is LIVE NOW!
https://www.kickstarter.com/projects/paulwheaton/low-tech
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
DateFormat Error
Parsing date..?
How do i print 1 as 01?
How to convert descriptive dates into Java Date format
Command Window Shutting Down....
Low Tech Laboratory Movie Kickstarter - March 2023
More...