SimpleDateFormat parse example

SimpleDateFormat parse example

Hi,

How to parse a date in Java program with the help of SimpleDateFormat class?

Tell me how to parse following variable:

String dtStr = "10-Dec-2017";

into a date variable.

Thanks

View Answers

July 21, 2017 at 2:45 AM

Hi,

Here is the example program:

package net.roseindia;

import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/*
 * Example of formatting date in Java 
 */
public class FormatDate {

    public static void main(String[] args) {

        String dt = "10-Dec-2017";
        String pattern = "dd-MMM-yyyy";
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern);
        Date date = null;
        try {
            date = simpleDateFormat.parse(dt);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        System.out.println("Date:" + date);

    }

}

In this example we are using the following code:

 SimpleDateFormat simpleDateFormat =
    new SimpleDateFormat(pattern);

The use following code to format it to date:

date = simpleDateFormat.parse(dt);

Thanks









Related Tutorials/Questions & Answers:
SimpleDateFormat parse example
SimpleDateFormat parse example  Hi, How to parse a date in Java program with the help of SimpleDateFormat class? Tell me how to parse following...;Hi, Here is the example program: package net.roseindia; import
SimpleDateFormat
SimpleDateFormat  Hi, What is the use of SimpleDateFormat class in Java? I want to learn it from many simple example programs. Thanks   Hi, SimpleDateFormat is a class in Java API which comes with the default JDK
Advertisements
Java SimpleDateFormat Example
Java SimpleDateFormat Example In this section we will discuss about how... a date using SimpleDateFormat. In this example we will create a simple Java... date format we may use the java.text.SimpleDateFormat class. SimpleDateFormat
PHP function parse_ini_file() and example
of the ini file in array form PHP parse_ini_file() Function with Example Code For PHP parse_ini_file() FunctionADS_TO_REPLACE_1 make a sample.ini... Syntax of PHP parse_ini_file() Function It is used to parse ini file.ini.
Locale with SimpleDateFormat - Java Beginners
a SimpleDateFormat object,specify a locale? Its just a good programming... SimpleDateFormat class. By defining the locales, you can display the dates in different formats.If you instantiate SimpleDateFormat class without a Locale
date_parse
accepted by strtotime() Example of Parse Date Function in PHP: <?php...date_parse() in PHP date_parse function returns associative array... error. Description on Date Parse Format in PHP array date_parse ( string $date
Formatting Date for a Locale Example
Formatting Date for a Locale Example       This example shows how to format Date using SimpleDateFormat class. In this program we are format date for different
Simple date formatter example
Simple date formatter example       In this section of simple date formatter example we are going to describe you how you can use different constructors of SimpleDateFormat
php parse ini array
php parse ini array  I wanted to parse a variable inside a variable value. Can any one give the example
DOM Parser Example to Parse A DOM Document
DOM Parser Example to Parse A DOM Document In this tutorial, we will discuss about how to parse(retrieve data) DOM Document. The XML DOM views an XML document as a tree-structure. In this program, we read the XML file and print
php parse ini file
php parse ini file  I need a simple and easy example to Parsing an ?advanced? INI file with PHP
date_parse_from_format
  date_parse_from_format date_parse_from_format function returns... about given date. Description on PHP Date Parse FormatADS_TO_REPLACE_1 array date_parse_from_format ( string $format , string $date ) Parameters of Date
php parse subdomain
php parse subdomain  Basically, looking for a example on how to let PHP to create subdomain automatically for each user? Is it possible to retrieve subdomain as a get variable
parse in iphone
parse in iphone  <p>{ itemCount: 2, subtotal: "$15.50", items:[ { title: "The Big Book of Foo", description: "Bestselling book of Foo by A.N. Other", imageUrl: "/images/books/12345.gif
JavaScript parse date
JavaScript parse date..., you will learn how to parse the date in JavaScript. JavaScript provides the function parse() that takes a date in string format and returns the equivalent
parse xml
parse xml   <STATES> <STATE sname="AndhraPradesh" > <DISTRICT dname="Ananthapur" > <address> Apollo...; </STATE> How to parse the above xml. please help me   Here
Kxml Parser Example
Kxml Parser Example       In this example we use "catching parsing events" way to parse the xml. Through 'catching parsing events', the parser traverses the XML
php parse string into array
php parse string into array  How can i parse a string into array and convert an array into string
php parse string to time
php parse string to time  I am looking for a solution to parse a string into a formatted date time string
php parse ini string
php parse ini string  Need to know how to parse the ini file to extract values
php parse string for url
php parse string for url  Do i need a regex to parse a URL-type string in PHP
parse url iphone sdk
parse url iphone sdk  How can i parse two different URL's using NSXMLParser
parse map in java
parse map in java  What is a Parser? Can you give the source code to parse map in Java
ModuleNotFoundError: No module named 'parse'
ModuleNotFoundError: No module named 'parse'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'parse' How to remove the ModuleNotFoundError: No module named 'parse'
ModuleNotFoundError: No module named 'parse-it'
ModuleNotFoundError: No module named 'parse-it'  Hi, My Python... 'parse-it' How to remove the ModuleNotFoundError: No module named 'parse... to install padas library. You can install parse-it python with following
ModuleNotFoundError: No module named 'parse_this'
ModuleNotFoundError: No module named 'parse_this'  Hi, My Python... 'parse_this' How to remove the ModuleNotFoundError: No module named 'parse_this' error? Thanks   Hi, In your python environment you
php parse string as php
php parse string as php  Best way of parsing a string within a string
php parse soap response
php parse soap response  What is soap and how can i convert a soap response to XML. Thanks in Advance
php parse string to float
php parse string to float  Is there any Regex or way to get float from a string
python date parse
python date parse  Hi, I want to parse the string date "20220131" into Python date. How to do that? Thanks
python date parse
python date parse  Hi, I want to parse the string date "20220131" into Python date. How to do that? Thanks
how to parse xml in j2me tutorial
how to parse xml in j2me tutorial   i want to parse xml file in j2me wireless toolkit.i saw ur examples & source code for parsing xml file in j2me & i try to execute same example on my pc i some how manage to run
example
example  example on Struts framework
example
example  example on Struts framework
php parse string as int
php parse string as int  While trying to pass string to int using int() i get the following error: Call to undefined function int() Why it is throwing an error
php parse string to date
php parse string to date  In my app i have a date string in the following format: $date = "08/20/2009"; Can you suggest how can i separate each part of the date
Mysql Date Parse
The Tutorial illustrate an example from 'Mysql Date Parse'. To understand and grasp... Mysql Date Parse       Mysql Date is used to parse the string date time in Date Format function
Version of ca.fuzzlesoft>json-parse dependency
List of Version of ca.fuzzlesoft>json-parse dependency
Version of com.infstory>auto-parse dependency
List of Version of com.infstory>auto-parse dependency
Version of com.parse>parse-android dependency
List of Version of com.parse>parse-android dependency
ModuleNotFoundError: No module named 'apk-parse'
ModuleNotFoundError: No module named 'apk-parse'  Hi, My Python... 'apk-parse' How to remove the ModuleNotFoundError: No module named 'apk-parse' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'circuitpython-parse'
ModuleNotFoundError: No module named 'circuitpython-parse'  Hi, My... named 'circuitpython-parse' How to remove the ModuleNotFoundError: No module named 'circuitpython-parse' error? Thanks   Hi
ModuleNotFoundError: No module named 'damask-parse'
ModuleNotFoundError: No module named 'damask-parse'  Hi, My Python... 'damask-parse' How to remove the ModuleNotFoundError: No module named 'damask-parse' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'deb-parse'
ModuleNotFoundError: No module named 'deb-parse'  Hi, My Python... 'deb-parse' How to remove the ModuleNotFoundError: No module named 'deb-parse' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'easy-parse'
ModuleNotFoundError: No module named 'easy-parse'  Hi, My Python... 'easy-parse' How to remove the ModuleNotFoundError: No module named 'easy-parse' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'easy-parse'
ModuleNotFoundError: No module named 'easy-parse'  Hi, My Python... 'easy-parse' How to remove the ModuleNotFoundError: No module named 'easy-parse' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'elasticsearch_parse'
ModuleNotFoundError: No module named 'elasticsearch_parse'  Hi, My... named 'elasticsearch_parse' How to remove the ModuleNotFoundError: No module named 'elasticsearch_parse' error? Thanks   Hi
ModuleNotFoundError: No module named 'iw-parse'
ModuleNotFoundError: No module named 'iw-parse'  Hi, My Python...-parse' How to remove the ModuleNotFoundError: No module named 'iw-parse... to install padas library. You can install iw-parse python with following
ModuleNotFoundError: No module named 'iw-parse'
ModuleNotFoundError: No module named 'iw-parse'  Hi, My Python...-parse' How to remove the ModuleNotFoundError: No module named 'iw-parse... to install padas library. You can install iw-parse python with following
ModuleNotFoundError: No module named 'iw-parse'
ModuleNotFoundError: No module named 'iw-parse'  Hi, My Python...-parse' How to remove the ModuleNotFoundError: No module named 'iw-parse... to install padas library. You can install iw-parse python with following

Ads