Java Custom Date Conversion class Example _java

Source: Internet
Author: User
Tags dateformat

Java Custom Date Conversion class

Copy Code code as follows:

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

Import org.apache.commons.beanutils.Converter;

/**
 * Custom java.util.Date Date converter
 *
 *
 */
public class Mydateconverter Implements Converter {

  @Override
 //convert value conversion c to type
 //existence class parameter purpose to write a generic converter if the conversion target type is determined , you can not use the C parameter
 public object convert (Class C, object value) {
  string strval = (String) value;
  //convert string to date---you need to format
  dateformat DateFormat = new SimpleDateFormat ("Yyyy-mm-dd") with a date ;
  try {
   date Date = Dateformat.parse (strval);
   return date;
  } catch (ParseException e) {
   e.printstacktrace ();
 &NBSP}
  return null;
&NBSP}
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.