In Java SimpleDateFormat article we'll see how to use java.text.SimpleDateFormat class, which provides methods to format date to string or parse string to date. The SimpleDateFormat is a class which inherits java.text.DateFormat class. Creating a SimpleDateFormat Instance: String pattern = "dd-MM-yyyy"; SimpleDateFormat sdf= new SimpleDateFormat(pattern); The pattern String parameter used for parsing and formatting of dates. The Pattern Examples are given at the end of the article. Related Links: Java Interview Questions Formatting Dates: String pattern = "dd-MM-yyyy"; SimpleDateFormat sdf = new SimpleDateFormat(pattern); String date = sdf.format(new Date()); System.out.println(date); Output: 25-09-2017 Parsing Dates: String pattern = "dd-MM-yyyy"; SimpleDateFormat sdf= new SimpleDateFormat(pattern); Date date = sdf.parse("25-09-2017"); Java SimpleDateFormat Example: Date to String Let's see an example to format date and time in java using java.text.SimpleDateFormat class. Continue rea...


I guess you came to this post by searching similar kind of issues in any of the search engine and hope that this resolved your problem. If you find this tips useful, just drop a line below and share the link to others and who knows they might find it useful too.

Stay tuned to my blogtwitter or facebook to read more articles, tutorials, news, tips & tricks on various technology fields. Also Subscribe to our Newsletter with your Email ID to keep you updated on latest posts. We will send newsletter to your registered email address. We will not share your email address to anybody as we respect privacy.


This article is related to


Java