Sunday, March 31, 2013

How to convert String to Date object



package com.swain.cell;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class StringDate {
       public static void main(String[] args) {
              DateFormat df = new SimpleDateFormat("dd/MM/yyyy");

              try {
                     Date today = df.parse("20/12/2005");
                     System.out.println("Today = " + df.format(today));
              } catch (ParseException e) {
                     e.printStackTrace();
              }
       }

}

No comments:

Post a Comment

How ChatGPT can Benefit Coding: Your Guide to Leveraging an AI Language Model

 Introduction: Hello, coders! Welcome to this blog post on how ChatGPT, an AI language model, can benefit your coding skills and projects. A...