Thursday, October 28, 2010

Java - Date Formats

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
String dt = sdf.format(payloadAccountRequest.getLastModifiedTime());
query.append(dt.replace(" ", "T") + "Z");

import java.sql.TimeStamp;
Calendar calendar = Calendar.getInstance();
calendar.add(calendar.YEAR, -5);
Timestamp lastModifiedTime = new Timestamp(calendar.getTimeInMillis());

public void compareTimeStamp() {
String sfdcTimeStampString = "2010-10-29T15:01:28.000Z";
sfdcTimeStampString = sfdcTimeStampString.replace("T", " ");
sfdcTimeStampString = sfdcTimeStampString.replace("Z", " ");

Calendar calendar = Calendar.getInstance();

Timestamp sdktimeStamp = new Timestamp(calendar.getTimeInMillis());

Timestamp sfdcTimeStamp = Timestamp.valueOf(sfdcTimeStampString);

if (sdktimeStamp.after(sfdcTimeStamp)) {
System.out.println("SDK Wins");
} else {
System.out.println("SFDC Wins");
}
}

setDate(new Date(System.currentTimeMillis()))

2 comments :

DeveloperBlog said...

calendar.setTime(date);
calendar.set(Calendar.HOUR_OF_DAY, 23);
calendar.set(Calendar.MINUTE, 59);
calendar.set(Calendar.SECOND, 59);
calendar.getTime();

DeveloperBlog said...

Timestamp endDateTimeStamp = new Timestamp(DateUtil.changeTimeOnDateTo235959(endDate).getTime())

// Below script tag for SyntaxHighLighter