List of usage examples for java.util Calendar setTime
public final void setTime(Date date)
Date
. From source file:Main.java
public static Calendar YYYYMMDDHHMMSSToCalendar(String str) { if (str != null) { Calendar cal = Calendar.getInstance(); try {// w w w . j av a 2s .c om SimpleDateFormat FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault()); cal.setTime(FORMAT.parse(str)); return cal; } catch (ParseException e) { return null; } } return null; }
From source file:Main.java
public static String getStringByDateFormat(String strDate, String format) { String mDateTime = null;//from www. j a va 2 s . co m try { Calendar c = new GregorianCalendar(); SimpleDateFormat mSimpleDateFormat = new SimpleDateFormat("MMM dd,yyyy kk:mm:ss aa", Locale.ENGLISH); c.setTime(mSimpleDateFormat.parse(strDate)); SimpleDateFormat mSimpleDateFormat2 = new SimpleDateFormat(format); mDateTime = mSimpleDateFormat2.format(c.getTime()); } catch (Exception e) { e.printStackTrace(); } return mDateTime; }
From source file:eu.annocultor.converters.solr.SolrPeriodsTagger.java
static Date endOfDay(Date date) { if (date == null) { return null; }//from ww w.j a v a 2 s. c o m Calendar calendar = GregorianCalendar.getInstance(TimeZone.getTimeZone("UTC")); calendar.setTime(date); calendar.set(Calendar.HOUR_OF_DAY, 23); calendar.set(Calendar.MINUTE, 59); calendar.set(Calendar.SECOND, 59); return calendar.getTime(); }
From source file:com.ekom.ekomerp.global.DateTimeUtils.java
public static Calendar getCalendarWithoutTime(Date date, Locale locale) { Calendar calendar = Calendar.getInstance(locale); calendar.setTime(date); calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 0); return calendar; }
From source file:com.collabnet.ccf.core.utils.DateUtil.java
public static Date convertDateToTimeZone(Date date, String toTimeZone) { Calendar toCal = new GregorianCalendar(TimeZone.getTimeZone(toTimeZone)); Calendar fromCal = new GregorianCalendar(); fromCal.setTime(date); toCal.set(fromCal.get(Calendar.YEAR), fromCal.get(Calendar.MONTH), fromCal.get(Calendar.DAY_OF_MONTH), fromCal.get(Calendar.HOUR_OF_DAY), fromCal.get(Calendar.MINUTE), fromCal.get(Calendar.SECOND)); toCal.set(Calendar.MILLISECOND, fromCal.get(Calendar.MILLISECOND)); return toCal.getTime(); }
From source file:storybook.ui.chart.jfreechart.ChartUtil.java
@SuppressWarnings("unchecked") public static TreeSet<Date> correctDates(TreeSet<Date> paramTreeSet) { TreeSet localTreeSet = new TreeSet(); Date localDate1 = (Date) paramTreeSet.first(); Calendar localCalendar1 = Calendar.getInstance(); localCalendar1.setTime(localDate1); int i = localCalendar1.get(Calendar.YEAR); if (i > 1900) { return paramTreeSet; }//w w w.j a va2 s .co m for (Date localDate2 : paramTreeSet) { Calendar localCalendar2 = Calendar.getInstance(); localCalendar2.setTime(localDate2); int j = localCalendar2.get(Calendar.YEAR); localDate2 = DateUtils.addYears(localDate2, 1900 - j); localTreeSet.add(localDate2); } return localTreeSet; }
From source file:model.manager.FileManager.java
public static boolean saveTemplate(ReportObject obj, String fileName) { Date now = new Date(); Calendar C = Calendar.getInstance(); C.setTime(now); ReportObjectXMLEncoder enc = new ReportObjectXMLEncoder(obj); String xml = enc.toXmlString(); File dir = new File(iDartProperties.exportDir); if (!dir.exists()) { if (!dir.mkdirs()) { log.error("Error creating directory: " + iDartProperties.exportDir); return false; }/* w w w . j a v a 2 s . c o m*/ } String pathname = iDartProperties.exportDir + File.separator + fileName; try { FileUtils.writeStringToFile(new File(pathname), xml); } catch (IOException E) { log.error("Error saving file: " + fileName); return false; } return true; }
From source file:com.worldline.easycukes.rest.utils.DateHelper.java
/** * Used to convert date value in json date format * * @param value/* w ww.j a v a 2 s . c o m*/ * @return */ public static String convertDateToJsonFormat(@NonNull final Date value) { log.info("setting the date value " + value + " to format json"); final Calendar calendar = Calendar.getInstance(); calendar.setTime(value); return calendar.get(Calendar.YEAR) + "-" + formatTo2Digit(calendar.get(Calendar.MONTH) + 1) + "-" + formatTo2Digit(calendar.get(Calendar.DAY_OF_MONTH)) + "T" + formatTo2Digit(calendar.get(Calendar.HOUR_OF_DAY)) + ":" + formatTo2Digit(calendar.get(Calendar.MINUTE)) + ":" + formatTo2Digit(calendar.get(Calendar.SECOND)) + ":" + calendar.get(Calendar.MILLISECOND) + "Z"; }
From source file:br.com.pontocontrol.controleponto.util.SwingUtils.java
public static Calendar getCalendarValueFromField(SimpleDateFormat formatter, JTextField field) throws ParseException { Calendar cal = Calendar.getInstance(); cal.setTime(getDateValueFromField(formatter, field)); return cal;// ww w . j a va 2 s . c o m }
From source file:com.vangent.hieos.xutil.hl7.date.Hl7Date.java
/** * * @param date//from w w w. ja va2 s .c o m * @return */ static public String toDTM_DefaultTimeZone(Date date) { Calendar c = new GregorianCalendar(); c.setTime(date); return Hl7Date.formatDTM(c); }