您的位置:首页 > 编程语言 > Java开发

java 时间格式转换

2012-08-26 17:03 239 查看
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) {
}

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: