package org.edx.mobile.util; import android.annotation.SuppressLint; import android.text.format.DateUtils; import com.google.gson.internal.bind.util.ISO8601Utils; import java.text.ParseException; import java.text.ParsePosition; import java.text.SimpleDateFormat; import java.util.Date; import org.edx.mobile.logger.Logger; @SuppressLint("SimpleDateFormat") public class DateUtil { private static final Logger logger = new Logger(DateUtil.class.getName()); /* * Converting Date in string format to Date object and converting the Current * Stamp */ public static Date convertToDate(String date) { if(date==null){ return null; } java.util.Date parsedate = null; final ParsePosition parsePosition = new ParsePosition(0); try { parsedate = ISO8601Utils.parse(date, parsePosition); logger.debug("Parsed Data"+parsedate); return parsedate; } catch (ParseException e) { logger.error(e); } return parsedate; } /** * @return The current date and time in a ISO 8601 compliant format. */ public static String getCurrentTimeStamp(){ return ISO8601Utils.format(new Date(), true); // Find todays date } /** * This function returns course start date in the MMMM dd, yyyy format */ public static String formatCourseNotStartedDate(String date) { try { SimpleDateFormat dateFormat = new SimpleDateFormat("MMMM dd, yyyy"); Date startDate = DateUtil.convertToDate(date); String formattedDate = dateFormat.format(startDate); return formattedDate; } catch (Exception e) { //This will be removed when the PR for log changes is merged with master logger.error(e); return null; } } }