Here you can find the source of isToday(String depDateTime)
Parameter | Description |
---|---|
dateTimeString | in format 2012-10-15T08:17:00 |
public static boolean isToday(String depDateTime)
//package com.java2s; //License from project: Apache License import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.TimeZone; public class Main { /**/* w ww . ja va 2 s . c o m*/ * Is a dateTime today * @param dateTimeString in format 2012-10-15T08:17:00 * @return true if today * */ public static boolean isToday(String depDateTime) { boolean isToday = false; Calendar depDate = parseCalendarString(depDateTime); int depDay = depDate.get(Calendar.DAY_OF_MONTH); Calendar now = getTimeNow(); int nowDay = now.get(Calendar.DAY_OF_MONTH); if (depDay == nowDay) { isToday = true; } return isToday; } /** *Converts a dateTimeString and makes a Calendar object * @param dateTimeString in format 2012-10-15T08:17:00 * @return Calendar object * */ public static Calendar parseCalendarString(String dateTimeString) { SimpleDateFormat dateFormat = new SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ss"); Date date = null; try { date = dateFormat.parse(dateTimeString); } catch (ParseException e) { e.printStackTrace(); } Calendar cal = Calendar.getInstance(); cal.setTimeZone(TimeZone.getTimeZone("Europe/Stockholm")); cal.setTime(date); return cal; } /** *Returns now * @return Calendar object * */ public static Calendar getTimeNow() { Calendar now = Calendar.getInstance(); now.setTime(new Date()); return now; } }