本文介绍了转换长字符串至今的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我从数据库获取日期值作为长值。我将这个为字符串使用的解析的功能。下面给出我的code
日期日期1 =新的SimpleDateFormat(MM / DD / YYYY)解析(strDate1);
但应用程序崩溃时,该code是executing.it会成功,如果执行
strDate1 =二零一二年十二月三十○日。
但我有这个值作为 12302012235 (pzudo值)。
我怎样才能做到这一点?
编辑:
我保存日期值DB为INTEGER。从DB我得到这个值,并转换为string.this是实际strDate1值
strDate1 =1346524199000
解决方案
请尝试以下code段:
日历C = Calendar.getInstance();
c.setTimeInMillis(的Long.parseLong(VAL));
日期D =(日期)c.getTime();
SimpleDateFormat的格式=新的SimpleDateFormat(DD / MM / YYYY);
字符串时间= format.format(D); //这个变量的时间包含日/月/年的格式的时间。
I am getting date value from DB as a long value. I am converting this to string to use parse function. Given below is my code
Date date1 = new SimpleDateFormat("MM/dd/yyyy").parse(strDate1);
But the app is crashing when this code is executing.it will successfully execute if the
strDate1="12/30/2012".
But i am having this value as "12302012235"(pzudo value).
How can i do this?
edit:
i am saving date value to DB as INTEGER. from DB i am getting this value and converting to string.this is the actual strDate1 value
strDate1="1346524199000"
解决方案
Try the following code segment:
Calendar c = Calendar.getInstance();
c.setTimeInMillis(Long.parseLong(val));
Date d = (Date) c.getTime();
SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy");
String time = format.format(d);//this variable time contains the time in the format of "day/month/year".
这篇关于转换长字符串至今的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!