将长字符串转换为日期

and*_*irl 2 android date

我从DB获取日期值作为值.我将此转换为字符串以使用解析函数.以下是我的代码

 Date date1 = new SimpleDateFormat("MM/dd/yyyy").parse(strDate1);
Run Code Online (Sandbox Code Playgroud)

但是当这个代码正在执行时,应用程序崩溃.如果执行该代码,它将成功执行

strDate1="12/30/2012".
Run Code Online (Sandbox Code Playgroud)

但我有这个值为" 12302012235 "(pzudo值).

我怎样才能做到这一点?

编辑:

我将日期值保存为DB为INTEGER.从DB我得到这个值并转换为string.this是实际的strDate1值

strDate1="1346524199000"
Run Code Online (Sandbox Code Playgroud)

shf*_*hrf 5

请尝试以下代码段:

        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".    
Run Code Online (Sandbox Code Playgroud)


归档时间:

查看次数:

10517 次

最近记录:

7 年,3 月 前