Java Base string date of transfer

Source: Internet
Author: User
Tags dateformat
Package com.iamzken.utils;

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

public class Dateformattest {public

	static void Main (string[] args) throws ParseException {
		// According to the time format in the database to new a corresponding SimpleDateFormat date converter, because the data extracted from the database format is similar to: 2015-10-10 23:20:20.23
		// The new SimpleDateFormat format is as follows:
		simpledateformat DateFormat = new SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss. S ");
		The date converter is used to convert the date string retrieved in the database to date type, as an example of "2015-10-10 23:20:20.23",
		//actually replace it with your own a.getcdate () date
		CDate = Dateformat.parse ("2015-10-10 23:20:20.23");
		Re-build a date converter, specify the format you want to convert
		String result = new SimpleDateFormat ("yyyy mm-month DD Day      hh time of the second s)." Format ( CDate);
		SYSTEM.OUT.PRINTLN (result);
	}

The summary is also two steps: 1. String is converted to date 2 by the SimpleDateFormat format of the string itself, and the date is converted to the target string through its own specified SimpleDateFormat format


When you can not forget the foundation Ah, what to do, basic skills must be solid ...

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.