Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Beginning Java
Search Coderanch
Advance search
Google search
Register / Login
Win a copy of
Spring Boot in Practice
this week in the
Spring
forum!
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
Tim Cooke
Ron McLeod
Jeanne Boyarsky
Paul Clapham
Sheriffs:
Liutauras Vilda
Henry Wong
Devaka Cooray
Saloon Keepers:
Tim Moores
Stephan van Hulst
Tim Holloway
Al Hobbs
Carey Brown
Bartenders:
Piet Souris
Mikalai Zaikin
Himai Minh
Forum:
Beginning Java
convert custom date format
Edward Durai
Ranch Hand
Posts: 223
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
consider,
i have a input like
13/12/2008 (dd/mm/yyyy) or 13-12-2008,
I want to change the format to 12/13/2008 (mm/dd/yyyy) or 12-13-2008.
Is it possible? Is there any function available?
Please advise.
Thank You<br />Edward
Jesper de Jong
Java Cowboy
Posts: 16084
88
I like...
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
You could parse the
string
with the input format, then format the resulting Date object with the output format. For example:
import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class Example { public static void main(String[] args) throws ParseException { String text = "13/12/2008"; DateFormat f1 = new SimpleDateFormat("dd/mm/yyyy"); Date date = f1.parse(text); DateFormat f2 = new SimpleDateFormat("mm/dd/yyyy"); String result = f2.format(date); System.out.println(result); } }
Jesper's Blog
-
Pluralsight Author Page
Did you see how Paul
cut 87% off of his electric heat bill with 82 watts of micro heaters
?
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Problems setting sql Date in prepared statement
SimpleDateFormat
Wrongly Date is updated
How to check a date is within range of dates ?
conversion of date
More...