java 时间格式转换
来源:互联网 发布:淘宝达人运营怎么做 编辑:程序博客网 时间:2024/04/29 20:00
import java.io.IOException;import java.text.ParseException;import java.text.SimpleDateFormat;import java.util.ArrayList;import java.util.Date;import java.util.regex.Matcher;import java.util.regex.Pattern;import org.apache.commons.httpclient.HttpClient;import org.apache.commons.httpclient.HttpException;import org.apache.commons.httpclient.HttpStatus;import org.apache.commons.httpclient.methods.GetMethod;import org.apache.commons.httpclient.methods.PostMethod;import org.htmlparser.Node;import org.htmlparser.Parser;import org.htmlparser.filters.AndFilter;import org.htmlparser.filters.HasAttributeFilter;import org.htmlparser.filters.TagNameFilter;import org.htmlparser.util.NodeList;import org.htmlparser.util.ParserException;import com.sun.org.apache.bcel.internal.generic.NEW;public class test {public static void main(String[] args) throws HttpException, IOException, ParserException {// TODO Auto-generated method stub//时间转换:String strSourcePattern = "yyyy-MM-dd HH:mm:ss";String strDestPattern = "yyyy-MM-dd"; String strTime = "2012-06-12 04:00:00"; try { SimpleDateFormat sourceDateFormat = new SimpleDateFormat(strSourcePattern, Locale.US); SimpleDateFormat destDateFormat = new SimpleDateFormat(strDestPattern, Locale.US); Date date = sourceDateFormat.parse(strTime); System.out.println(destDateFormat.format(date)); } catch (ParseException e) { } }}