Another Salesforce blog!!!

Salesforce, Apex

APEX DATE FORMAT

date format

public static String formatDatetime(Datetime dt) { return dt.format(‘yyyy-dd-MM’); } public static Datetime parseDatetime(String dateStr) { if (dateStr==null) return null; // split the original string String[] tokens = dateStr.split(‘ ‘, 0); //String dayOfWeek = tokens[0]; Integer day = Integer.valueOf(tokens[1]); Integer month = monthToInteger.get(tokens[2]); Integer year = Integer.valueOf(tokens[3]); String[] timeOfDay = tokens[4].split(‘:’); String offset = tokens[5]; // […]