Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

converting long string to date [duplicate]

Tags:

date

android

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"
like image 221
andro-girl Avatar asked Jun 09 '26 10:06

andro-girl


2 Answers

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".    
like image 135
shfshrf Avatar answered Jun 11 '26 21:06

shfshrf


Try this,

SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd");
    Date dateD=new Date();
    dateD.setTime(LongTime);
    date=dateFormat.format(dateD);
like image 26
Jin Avatar answered Jun 11 '26 22:06

Jin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!