TestingDocs.com
Software Testing website
  • Automation
    • Selenium
    • JBehave Framework
  • Tutorials
    • MySQL Tutorials
    • Testlink
    • Maven
    • Git
  • IDEs
    • IntelliJ IDEA
    • Eclipse
  • Flowcharts
    • Flowgorithm
    • Raptor
  • About

Automation

Convert String to Date in Java

Overview

In this tutorial, we will convert String to Date in Java sample program.

Sample Java Program

import java.util.*;
import java.text.*;

/**************************************
 * 
 * Sample String to Date Java Program
 * Java Tutorials
 * www.TestingDocs.com
 * 
 **************************************/
public class StringToDateDemo {
 public static void main(String[] args) {
 try { 
 String dateStr ="21-Dec-2012";
 Date date; 
 DateFormat formatter; 
 formatter = new SimpleDateFormat("dd-MMM-yyyy");
 date = (Date)formatter.parse(dateStr); 
 Calendar calendar=Calendar.getInstance();
 calendar.setTime(date);
 System.out.println("Date is :=" + date );
 } catch (Exception exp)
 {
 System.out.println("Exception :"+exp);
 } 
 }
} 

Screenshot

Related Posts

Automation /

Code Coverage Tools

Automation /

Selenium 4 Project Setup on Ubuntu Linux

Automation /

Testing webpage mobile-friendliness using a tool

Automation /

Error Severity Metrics

Automation /

Automation Environment Setup Verification

‹ UML Class Diagram› Types of Software Test Plans

Recent Posts

  • Scaler Academy – An Online Learning Platform
  • Difference between PHP and JavaScript?
  • MS Access Data Types
  • Install RAPTOR Avalonia on CentOS
  • Download RAPTOR Avalonia Edition on Windows
  • npm doctor command
  • Build & Run CLion Project
  • Create New CLion C Project on Windows
  • Configure CLion Toolchains on Windows
  • Launch CLion IDE on Windows

Back to Top

Links

  • Contact
  • Privacy Policy
  • Cookie Policy

www.TestingDocs.com