cancel
Showing results for 
Search instead for 
Did you mean: 

How to convert long int date to Date datatype

Former Member
0 Kudos

I'm trying to display an attribute of a PCD object - the "LastChangedAt" date/time from a System Landscape object. The value returns as a String, in the format "1134681210082". How can I convert that number into a Date?

Thanx,

Dale

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Dale,

Try this..

Date createdDate = new Date(Long.parseLong(result.getAttribute("com.sap.portal.pcd.gl.LastChangedAt")));

You can format this date again in whatever format you want.

like this..

SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss ");

Date createdDate = new Date(Long.parseLong(result.getAttribute("com.sap.portal.pcd.gl.LastChangedAt")));

String createdAt = simpleDateFormat.format(createdDate);

Hope it helps.

Regards,

Karthick K Eswaran

Answers (2)

Answers (2)

Former Member
0 Kudos

Thanx! I also found that I was importing Date from HTMLB instead of java.util, so I was getting an error on formatting the output. But all is well now - thanx again.

Dale

Murali_Shanmu
Active Contributor
0 Kudos

Hi

I believe the system stores date as Milliseconds from Jan 1 1970 in the form of a string. So try

Date myDate = new Date( new Long( <Date Value> ).longValue());

Hope this works ...