Reputation: 135
i'm trying to retrieve the current date via unix time like this:
long unixTime = System.currentTimeMillis()/1000;
Date d = new Date(unixTime);
StringBuffer tmp = new StringBuffer();
tmp.append(d.getYear());
tmp.append(" - ");
tmp.append(d.getMonth());
tmp.append(" - ");
tmp.append(d.getDay());`
When i later print this out via tmp.getString()
i get the following date 70 - 0 - 4 , is there something im missing ?
//Thx in advance
Upvotes: 0
Views: 806
Reputation: 200160
Those methods you are using are deprecated. You better use the GregorianCalendar
class:
GregorianCalendar gregorianCalendar=new GregorianCalendar();
StringBuffer tmp = new StringBuffer();
tmp.append(gregorianCalendar.get(GregorianCalendar.YEAR));
tmp.append(" - ");
tmp.append(gregorianCalendar.get(GregorianCalendar.DAY_OF_MONTH));
tmp.append(" - ");
tmp.append(gregorianCalendar.get(GregorianCalendar.MONTH));
Upvotes: 2
Reputation: 14895
Date takes milliseconds since epoch. So just don't divide unixTime by 1000.
Upvotes: 0