{$HH:mm:ss$}虚拟店铺货源怎...

&&国之画&&&& &&&&&&
&& &&&&&&&&&&&&&&&&&&
鲁ICP备号-4
打开技术之扣,分享程序人生!在java中如何实现把String类型转化为Time类型,例如:hh:mm:ss格式_百度知道
在java中如何实现把String类型转化为Time类型,例如:hh:mm:ss格式
java中实现把String类型的时间转换成Time类型的时间可以使用SimpleDateFormat来转换。
具体事例代码实现如下:public class Demo2 {
public static void main(String[] args) {
String str = & 12:12:12&;//定义一个字符型的时间
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(&yyyy-MM-dd HH:mm:ss&);
Date date =
date = (Date) simpleDateFormat.parse(str);//将这个字符型的时间转换成Date型的时间
} catch (ParseException e) {
e.printStackTrace();
System.out.println(date.toString());
SimpleDateFormat 是 Java 中一个非常常用的类,该类用来对日期字符串进行解析和格式化输出。
其他类似问题
为您推荐:
提问者采纳
Time.valueOf(String s) Converts a string in JDBC time escape format to a Time value.
提问者评价
感谢楼上各位的帮忙,我通过二楼和三楼的帮助,调试通过了,在此万分感谢。
其他3条回答
但是这些字母是固定的;dd-MM-yyyy hh、字符串转化为日期利用SimpleDateFormat类;引号里面可以随意写:ss&quot,而不写日期,或者是些时间hh。 2;dd-MM-yyyy hh:mm:mm:ss&):SimpleDateFormat(&quot.parse(timeStr).format(new Date()),比如:只写dd-MM-yyyy、日期转化为固定字符串SimpleDateFormat(&quot:)。1:ss
public class SQLDateTest {
public static void main(String[] args) {
// TODO Auto-generated method stub
DateFormat df = new SimpleDateFormat(&hh:mm:ss&);// 拼写有误,应为MM
Date date = new Date(0);
date = new Date(df.parse(&12:56:15&).getTime());
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.err.println(date);
//打印结果是(因为之规定了了时分秒,没有规定年月日
//因此日期显示为默认日期,也就是new Date().getTime为0的那天
//sql.Date的toString只显示年月日..
也就是说对于年月日只要规定好格式..作为SimpleDateFormat构造函数的参数.
比如题目中的hh:m...
Time.valueOf(String s)
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁二次元同好交流新大陆
扫码下载App
汇聚2000万达人的兴趣社区下载即送20张免费照片冲印
扫码下载App
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!&&|&&
我市一只小小小鸟,我要飞的更高。
LOFTER精选
网易考拉推荐
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
阅读(1256)|
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
历史上的今天
loftPermalink:'',
id:'fks_085070',
blogTitle:'yyyy-MM-dd HH:mm:ss格式转化成毫秒数(long)',
blogAbstract:'package com.fzd.bbs.import java.sql.Dimport java.text.SimpleDateFpublic class DateFormate {&& & public&& static&& long&& formatDate(String&& dateStr){&&&&&&&& java.sql.Date&& d=&&&&&&&& try{&&&&&&&&&&&&&&&& SimpleDateFormat&& sf&& =&& new&& SimpleDateFormat(\"yyyy-MM-dd HH:mm:ss\");',
blogTag:'',
blogUrl:'blog/static/',
isPublished:1,
istop:false,
modifyTime:4,
publishTime:9,
permalink:'blog/static/',
commentCount:0,
mainCommentCount:0,
recommendCount:0,
bsrk:-100,
publisherId:0,
recomBlogHome:false,
currentRecomBlog:false,
attachmentsFileIds:[],
groupInfo:{},
friendstatus:'none',
followstatus:'unFollow',
pubSucc:'',
visitorProvince:'',
visitorCity:'',
visitorNewUser:false,
postAddInfo:{},
mset:'000',
remindgoodnightblog:false,
isBlackVisitor:false,
isShowYodaoAd:false,
hostIntro:'我市一只小小小鸟,我要飞的更高。',
hmcon:'1',
selfRecomBlogCount:'0',
lofter_single:''
{list a as x}
{if x.moveFrom=='wap'}
{elseif x.moveFrom=='iphone'}
{elseif x.moveFrom=='android'}
{elseif x.moveFrom=='mobile'}
${a.selfIntro|escape}{if great260}${suplement}{/if}
{list a as x}
推荐过这篇日志的人:
{list a as x}
{if !!b&&b.length>0}
他们还推荐了:
{list b as y}
转载记录:
{list d as x}
{list a as x}
{list a as x}
{list a as x}
{list a as x}
{if x_index>4}{break}{/if}
${fn2(x.publishTime,'yyyy-MM-dd HH:mm:ss')}
{list a as x}
{if !!(blogDetail.preBlogPermalink)}
{if !!(blogDetail.nextBlogPermalink)}
{list a as x}
{if defined('newslist')&&newslist.length>0}
{list newslist as x}
{if x_index>7}{break}{/if}
{list a as x}
{var first_option =}
{list x.voteDetailList as voteToOption}
{if voteToOption==1}
{if first_option==false},{/if}&&“${b[voteToOption_index]}”&&
{if (x.role!="-1") },“我是${c[x.role]}”&&{/if}
&&&&&&&&${fn1(x.voteTime)}
{if x.userName==''}{/if}
网易公司版权所有&&
{list x.l as y}
{if defined('wl')}
{list wl as x}{/list}java - Convert a timestamp EEE, d MMM yyyy HH:mm:ss GMT format to yyyy-MM-dd'T'HH:mm:ss'Z' format? - Stack Overflow
to customize your list.
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.
J it only takes a minute:
Join the Stack Overflow community to:
Ask programming questions
Answer and help your peers
Get recognized for your expertise
I want to convert the timestamp Wed, 20 Feb :23 GMT to T11:41:23Z . How can I do this? I want to ISO-8601 in UTC format(T04:51:03Z).
My code is below
Date date=new Date();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
String strDate = date.toString();
Date dt = formatter.parse(strDate );
System.out.println("Date " +dt);
Output is:
Exception in thread "main" java.text.ParseException: Unparseable date: "Wed Feb 20 03:50:03 PST 2013"
8,36611425
user899876
You need 2 DateFormatters, one for parsing and one for output. You have the one for output.
EDIT: Output works like this:
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
String output = formatter.format(new Date());
System.out.println("Date " + output);
Consider using , which has built in support for parsing and outputting ISO-format date strings.
new DateTime(DateTimeZone.UTC).toString()
81.3k67796
You already have a Date object. You just need to
it to String.
formatter.format(date) should give you the desired result if the pattern in the SimpleDateFormat constructor is valid.
With the above implementation your code looks like this:
Date date = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
String dt = formatter.format(date);
System.out.println("Date " + dt);
Which results in an output like - Date T17:39:45Z.
7,50021526
DateFormat format = new SimpleDateFormat ("yyyy-MM-dd'T'HH:mm:ss'Z'");
format.setTimeZone (TimeZone.getTimeZone ("UTC"));
Date date = new Date ();
System.out.println ("Date is: " + format.format (date));
8,36611425
Its your format what is wrong, use:
"EEE MMM dd HH:mm:ss Z yyyy" that is what is comming out of the exception, in the question you have "EEE, dd MMM yyyy HH:mm:ss Z" for Wed, 20 Feb :23 GMT
Date date = new Date();
SimpleDateFormat formatter = new SimpleDateFormat(
"EEE MMM dd HH:mm:ss Z yyyy");
String strDate = date.toString();
dt = formatter.parse("Wed Feb 20 03:50:03 PST 2013");
} catch (ParseException e) {
e.printStackTrace();
System.out.println("Date " + dt);
System.out.println(new Timestamp(new Date().getTime()));
Your Answer
Sign up or
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Post as a guest
By posting your answer, you agree to the
Stack Overflow works best with JavaScript enabled}

我要回帖

更多关于 网店货源 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信