怎样把simpledateformat时区转成字符串

利用SimpleDateFormat将String转换为格式化的日期
// 将解析为:
private void parseTime1() {
String time = "";
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd");
// SimpleDateFormat的parse(String time)方法将String转换为Date
Date date = simpleDateFormat.parse(time);
simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
// SimpleDateFormat的format(Date date)方法将Date转换为String
String formattedTime = simpleDateFormat.format(date);
System.out.println("---->将" + time + "解析为:" + formattedTime);
} catch (Exception e) {
// 将09解析为: 08:50:09
private void parseTime2() {
String time = "09";
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
// SimpleDateFormat的parse(String time)方法将String转换为Date
Date date = simpleDateFormat.parse(time);
simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
// SimpleDateFormat的format(Date date)方法将Date转换为String
String formattedTime = simpleDateFormat.format(date);
System.out.println("---->将" + time + "解析为:" + formattedTime);
} catch (Exception e) {下次自动登录
现在的位置:
& 综合 & 正文
Java日期转换SimpleDateFormat格式大全
判断是否为合法的日期时间字符串?
24小时制时间显示:
public class Datetime {
public static void main(String args[]){
java.util.Date current=new java.util.Date();
java.text.SimpleDateFormat sdf=new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String c=sdf.format(current);
System.out.println(c);
12小时制时间显示:
public class Datetime {
public static void main(String args[]){
java.util.Date current=new java.util.Date();
java.text.SimpleDateFormat sdf=new java.text.SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
String c=sdf.format(current);
System.out.println(c);
两者区别:yyyy-MM-dd HH:mm:
yyyy-MM-dd hh:mm:ss
日期或时间元素
Era 标志符
年中的月份
July; Jul; 07
年中的周数
月份中的周数
年中的天数
月份中的天数
月份中的星期
星期中的天数
Tuesday; Tue
Am/pm 标记
一天中的小时数(0-23)
一天中的小时数(1-24)
am/pm 中的小时数(0-11)
am/pm 中的小时数(1-12)
小时中的分钟数
分钟中的秒数
Pacific Standard Time; PST; GMT-08:00
-------------------------------------------------------------
public class JudgeDate {
* 判断是否为合法的日期时间字符串
* @param str_input
* @符合为true,不符合为false
*/public static
boolean isDate(String str_input,String rDateFormat){if (!isNull(str_input)) {
SimpleDateFormat formatter = new SimpleDateFormat(rDateFormat);
formatter.setLenient(false);
formatter.format(formatter.parse(str_input));
} catch (Exception e) {
}public static boolean isNull(String str){if(str==null)else}public static void main(String args[]){String str="";if(isDate(str,"yyyy.MM.dd")|isDate(str,"yyyy-MM-dd"))System.out.print("This is true");elseSystem.out.println(str);}}
&&&&推荐文章:
【上篇】【下篇】(Android君)
(?Scorpo?)
(?Scorpo?)
第三方登录:怎么讲字符串格式格林威治时间转换为Date类型【java吧】_百度贴吧
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&签到排名:今日本吧第个签到,本吧因你更精彩,明天继续来努力!
本吧签到人数:0成为超级会员,使用一键签到本月漏签0次!成为超级会员,赠送8张补签卡连续签到:天&&累计签到:天超级会员单次开通12个月以上,赠送连续签到卡3张
关注:631,704贴子:
Wed Jun 5 00:00:00 GMT+(存在数据库中,为String类型)怎么讲这个转换为Date类型 如
simplateDateFormat s = new simplateDateFormat (yyyy-MM-dd )s.parse(String)
SimpleDateFormate format1=new SimpleDateFormate("yyyy-MM-dd");// String转Date date=str = "";
date = format1.parse(str);
} catch (ParseException e) { e.printStackTrace();
额。。。不知道是不是你想要的,要是不是,就请另请高人
API里面不是有吗?
simplateDateFormat
搞反了,你的是String转date
String str = "Wed Jun 5 00:00:00 GMT+08:00 2013";//在08与00之间加:java.text.SimpleDateFormat sdf = new SimpleDateFormat("E MMM dd HH:mm:ss z yyyy",Locale.US);System.out.println(sdf.format(new Date()));Dtry {d = sdf.parse(str);sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");System.out.println(sdf.format(d));} catch (ParseException e) {// TODO Auto-generated catch blocke.printStackTrace();}
登录百度帐号推荐应用14:24 提问
java怎么把转换成字符串转换成中国人习惯看的时间。
public class Test{
public static void main(String[] args) throws Exception {
String str="";
Date d=new SimpleDateFormat("yyyy/MM/dd").parse(str);
System.out.println(d);}
打印出来的结果是
Mon Apr 13 00:00:00 CST 2015
我想打印出来的结果是 ,类型是时间类型的,怎么破
按赞数排序
----------------------同志你好,我是CSDN问答机器人小N,奉组织之命为你提供参考答案,编程尚未成功,同志仍需努力!
SimpleDateForm sd = new SimpleDateFormat("yyyy/MM/dd");
System.out.println(sd.format(new Date()));
SimpleDateForm sd = new SimpleDateFormat("yyyy/MM/dd");
System.out.println(sd.format(new Date()));
1.Date是一个对象,通过看system.out.println的实现可以发现,
java.io.PrintStream
public void print(Object obj) {
write(String.valueOf(obj));
使用system.out.println()方法打印对象 会默认调用这个对象toString()方法。
2.Date的toString()方法的实现就是将时间按照一定格式依次放入到StringBuilder中,然后打印出来。
3.所以有两种方法,重写toString()方法,或者就将时间转换成字符串然后打印,这种方法可以看上面一楼的实现
其他相似问题

我要回帖

更多关于 simpledateformat用法 的文章

 

随机推荐