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
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:
Tim Cooke
Campbell Ritchie
paul wheaton
Jeanne Boyarsky
Ron McLeod
Sheriffs:
Paul Clapham
Devaka Cooray
Saloon Keepers:
Tim Holloway
Carey Brown
Piet Souris
Bartenders:
Forum:
Beginning Java
convert custom date format
Edward Durai
Ranch Hand
Posts: 223
posted 16 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 16 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...