List of usage examples for java.util Calendar clear
public final void clear()
Calendar
undefined. From source file:com.pureinfo.tgirls.servlet.GetWelcomeMsg.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { JsonBase result = new JsonBase(); response.setContentType("text/json; charset=utf-8"); User loginUser = CookieUtils.getLoginUser(request, response); if (loginUser == null) { result.setErrorCode(JsonBase.ErrorCode.ERROR.getCode()); result.setErrorMsg(""); response.getWriter().write(result.toString()); return;/*from w w w . j av a 2 s . c o m*/ } IUserMgr usermgr = null;//(IUserMgr) ArkContentHelper.getContentMgrOf(User.class); try { usermgr = (IUserMgr) ArkContentHelper.getContentMgrOf(User.class); if (loginUser.getLastLoginTime() == null) { loginUser.setLastLoginTime(new Date()); usermgr.save(loginUser); } } catch (PureException e1) { logger.error(e1); result.setErrorCode(JsonBase.ErrorCode.ERROR.getCode()); if (StringUtils.isNotEmpty(e1.getMessage())) { result.setErrorMsg(e1.getMessage()); } else { result.setErrorMsg(""); } response.getWriter().write(result.toString()); return; } if (DateUtils.isSameDay(loginUser.getLastLoginTime(), new Date())) { result.setErrorCode(JsonBase.ErrorCode.ERROR.getCode()); result.setErrorMsg("???"); response.getWriter().write(result.toString()); return; } else { //???? createNormalRandomEvent(loginUser); } Calendar now = Calendar.getInstance(); int m = now.get(Calendar.MONTH); int d = now.get(Calendar.DAY_OF_MONTH); List<RandomEvent> todayEvents = (List<RandomEvent>) cache.get(WELCOME_EVENT_KEY + "." + m + "." + d); if (todayEvents == null) { todayEvents = new ArrayList<RandomEvent>(); logger.debug("today events is empty. reload."); List<RandomEvent> allWelcomeRandomEvents = null; try { allWelcomeRandomEvents = getWelcomeEvents(); } catch (PureException e) { logger.error("error when get welcome events.", e); } if (allWelcomeRandomEvents == null || allWelcomeRandomEvents.isEmpty()) { logger.debug("all welcome events is empty."); result.setErrorCode(JsonBase.ErrorCode.ERROR.getCode()); result.setErrorMsg("?"); response.getWriter().write(result.toString()); return; } List<RandomEvent> normalEvents = new ArrayList<RandomEvent>();// Calendar c1 = Calendar.getInstance();// Calendar.getInstance(); Calendar today = Calendar.getInstance(); for (Iterator<RandomEvent> iterator = allWelcomeRandomEvents.iterator(); iterator.hasNext();) { RandomEvent randomEvent = iterator.next(); String month_day = randomEvent.getEventMonthDay(); if (StringUtils.isNotEmpty(month_day)) { try { int i = month_day.indexOf("-"); int month = NumberUtils.toInt(month_day.substring(0, i), -1); int day = NumberUtils.toInt(month_day.substring(i + 1), -1); c1.clear(); c1 = Calendar.getInstance(); // logger.debug("the random event [" + randomEvent.getEventInfo() + "] month:" + month // + " ,day: " + day); if (month != -1) { c1.set(Calendar.MONTH, month - 1); } if (day != -1) { c1.set(Calendar.DAY_OF_MONTH, day); } if (DateUtils.isSameDay(c1, today)) { todayEvents.add(randomEvent); } } catch (Exception e) { } } else { normalEvents.add(randomEvent); } } if (todayEvents == null || todayEvents.isEmpty()) { if (normalEvents.isEmpty()) { logger.debug("today events is empty, and normal events is empty too."); result.setErrorCode(JsonBase.ErrorCode.ERROR.getCode()); result.setErrorMsg("?"); response.getWriter().write(result.toString()); return; } else { todayEvents.addAll(normalEvents); } } Collections.sort(todayEvents, new BeanComparator("eventScale")); todayTotalScale = 0; for (Iterator<RandomEvent> iterator = todayEvents.iterator(); iterator.hasNext();) { RandomEvent randomEvent2 = iterator.next(); todayTotalScale += randomEvent2.getEventScale(); } cache.put(WELCOME_EVENT_KEY + "." + m + "." + d, todayEvents); } if (todayEvents == null || todayEvents.isEmpty()) { logger.debug("today events is empty, system events is empty ."); result.setErrorCode(JsonBase.ErrorCode.ERROR.getCode()); result.setErrorMsg("?"); response.getWriter().write(result.toString()); return; } int random = new Random().nextInt(todayTotalScale); RandomEvent todayEvent = null; int start = 0; int end = 0; for (int i = 0; i < todayEvents.size(); i++) { if (i == 0) { start = 0; end = todayEvents.get(i).getEventScale(); } else { start = end; end = end + todayEvents.get(i).getEventScale(); } if (random >= start && random < end) { todayEvent = todayEvents.get(i); break; } } if (todayEvent == null) { result.setErrorCode(JsonBase.ErrorCode.ERROR.getCode()); result.setErrorMsg("?"); response.getWriter().write(result.toString()); return; } try { result.put("event", new JSONObject(todayEvent)); logger.info("welcome event[" + todayEvent.getEventInfo() + "]"); loginUser.setFunds(loginUser.getFunds() + todayEvent.getEventMoney()); loginUser.setAssets(loginUser.getAssets() + todayEvent.getEventMoney()); loginUser.setLastLoginTime(new Date()); usermgr.save(loginUser); request.getSession().setAttribute(ArkHelper.ATTR_LOGIN_USER, loginUser); } catch (Exception e) { logger.error(e); result.setErrorCode(JsonBase.ErrorCode.ERROR.getCode()); if (StringUtils.isNotEmpty(e.getMessage())) { result.setErrorMsg(e.getMessage()); } else { result.setErrorMsg(""); } response.getWriter().write(result.toString()); return; } logger.debug("event:" + result.toString()); request.getSession().setAttribute(ArkHelper.ATTR_LOGIN_USER, loginUser); response.getWriter().write(result.toString()); return; }
From source file:com.zimbra.cs.imap.ImapRequest.java
Date readDate(boolean datetime, boolean checkRange) throws ImapParseException { String dateStr = (peekChar() == '"' ? readQuoted() : readAtom()); if (dateStr.length() < (datetime ? 26 : 10)) { throw new ImapParseException(tag, "invalid date format"); }//w ww .j av a 2s. com Calendar cal = new GregorianCalendar(); cal.clear(); int pos = 0, count; if (datetime && dateStr.charAt(0) == ' ') { pos++; } count = 2 - pos - (datetime || dateStr.charAt(1) != '-' ? 0 : 1); validateDigits(dateStr, pos, count, cal, Calendar.DAY_OF_MONTH); pos += count; validateChar(dateStr, pos, '-'); pos++; validateMonth(dateStr, pos, cal); pos += 3; validateChar(dateStr, pos, '-'); pos++; validateDigits(dateStr, pos, 4, cal, Calendar.YEAR); pos += 4; if (datetime) { validateChar(dateStr, pos, ' '); pos++; validateDigits(dateStr, pos, 2, cal, Calendar.HOUR); pos += 2; validateChar(dateStr, pos, ':'); pos++; validateDigits(dateStr, pos, 2, cal, Calendar.MINUTE); pos += 2; validateChar(dateStr, pos, ':'); pos++; validateDigits(dateStr, pos, 2, cal, Calendar.SECOND); pos += 2; validateChar(dateStr, pos, ' '); pos++; boolean zonesign = dateStr.charAt(pos) == '+'; validateChar(dateStr, pos, zonesign ? '+' : '-'); pos++; int zonehrs = validateDigits(dateStr, pos, 2, cal, -1); pos += 2; int zonemins = validateDigits(dateStr, pos, 2, cal, -1); pos += 2; cal.set(Calendar.ZONE_OFFSET, (zonesign ? 1 : -1) * (60 * zonehrs + zonemins) * 60000); cal.set(Calendar.DST_OFFSET, 0); } if (pos != dateStr.length()) { throw new ImapParseException(tag, "excess characters at end of date string"); } Date date = cal.getTime(); if (checkRange && date.getTime() < 0) { throw new ImapParseException(tag, "date out of range"); } return date; }
From source file:core.module.codec.EncodeDecodeOtaMessage.java
public static Calendar decode19BitDate(long minute) { long hour;// ww w .jav a2 s .c o m long day; long month; month = 0; minute = convert19BitDateMinutes(minute); hour = minute / 60; minute %= 60; // minutes correct if (0 == minute) { if (!(hour % 3 != 0)) { minute = 1; } } if ((minute == 59) && ((hour % 3) == 2)) // rounding up!! { minute = 0; ++hour; } day = hour / 24; hour %= 24; // hours correct if (day < 31) // januari { month = 1; } else { day -= 31; } if (0 == month) { if (day < 29) // februari { month = 2; } else { day -= 29; } } if (0 == month) { if (day < 31) // maart { month = 3; } else { day -= 31; } } if (0 == month) { if (day < 30) // april { month = 4; } else { day -= 30; } } if (0 == month) { if (day < 31) // mei { month = 5; } else { day -= 31; } } if (0 == month) { if (day < 30) // juni { month = 6; } else { day -= 30; } } if (0 == month) { if (day < 31) // juli { month = 7; } else { day -= 31; } } if (0 == month) { if (day < 31) // augustus { month = 8; } else { day -= 31; } } if (0 == month) { if (day < 30) // september { month = 9; } else { day -= 30; } } if (0 == month) { if (day < 31) // oktober { month = 10; } else { day -= 31; } } if (0 == month) { if (day < 30) // november { month = 11; } else { day -= 30; } } if (0 == month) { if (day < 31) // december { month = 12; } else { day -= 31; } } ++day; Calendar cal = Calendar.getInstance(); // if month > this month then year is last year // if month <= this month, then year is this year int currentYear = cal.get(cal.YEAR); if (month > cal.get(cal.MONTH) + 1) { currentYear--; } // FOR TESTING AGAINST FILE DATES... currentYear = 2004; cal.clear(); cal.set(currentYear, (int) (month - 1), (int) day, (int) hour, (int) minute, 0); //logger.finer( "mm/dd/yyyy hh:mm=" + month + "/" + day + "/" + currentYear + " " + hour + ":" + minute ); return cal; }
From source file:org.exoplatform.addon.pulse.service.ws.RestActivitiesStatistic.java
private long getTotalPlfDownloadDataFromJson(String json, Date startDate) { Date today = new Date(); Calendar cal = Calendar.getInstance(); cal.clear(); cal.setTime(today);/*from www .j ava 2 s .com*/ cal.add(Calendar.DATE, 1); Date nexDate = cal.getTime(); cal.clear(); if (startDate.after(nexDate)) return 0L; // Do not get data of future try { org.json.simple.JSONObject jsonObj = (org.json.simple.JSONObject) JSONValue.parseWithException(json); //in case request to get data in future, return 0 String startDateStr = partString(startDate, "yyyy-MM-dd"); String returnStartDateStr = jsonObj.get("start_date").toString(); if (returnStartDateStr.substring(0, 10).equalsIgnoreCase(startDateStr) == false) { return 0L; } Long total = Long.parseLong(jsonObj.get("total") + ""); return total; } catch (ParseException e) { // TODO Auto-generated catch block LOG.error(e.getMessage()); } catch (Exception e) { LOG.error(e.getMessage()); } return 0l; }
From source file:org.jfree.data.time.TimeSeriesTest.java
@Test public void testFindValueRange2() { TimeZone tzone = TimeZone.getTimeZone("Europe/London"); Calendar calendar = new GregorianCalendar(tzone, Locale.UK); calendar.clear(); calendar.set(2014, Calendar.FEBRUARY, 23, 6, 0); long start = calendar.getTimeInMillis(); calendar.clear();//from ww w . j a v a 2 s . com calendar.set(2014, Calendar.FEBRUARY, 24, 18, 0); long end = calendar.getTimeInMillis(); Range range = new Range(start, end); TimeSeries ts = new TimeSeries("Time Series"); assertNull(ts.findValueRange(range, TimePeriodAnchor.START, tzone)); assertNull(ts.findValueRange(range, TimePeriodAnchor.MIDDLE, tzone)); assertNull(ts.findValueRange(range, TimePeriodAnchor.END, tzone)); ts.add(new Day(23, 2, 2014), 5.0); assertTrue(ts.findValueRange(range, TimePeriodAnchor.START, tzone).isNaNRange()); assertEquals(new Range(5.0, 5.0), ts.findValueRange(range, TimePeriodAnchor.MIDDLE, tzone)); assertEquals(new Range(5.0, 5.0), ts.findValueRange(range, TimePeriodAnchor.END, tzone)); ts.add(new Day(24, 2, 2014), 6.0); assertEquals(new Range(6.0, 6.0), ts.findValueRange(range, TimePeriodAnchor.START, tzone)); assertEquals(new Range(5.0, 6.0), ts.findValueRange(range, TimePeriodAnchor.MIDDLE, tzone)); assertEquals(new Range(5.0, 5.0), ts.findValueRange(range, TimePeriodAnchor.END, tzone)); ts.clear(); ts.add(new Day(24, 2, 2014), null); assertTrue(ts.findValueRange(range, TimePeriodAnchor.START, tzone).isNaNRange()); assertTrue(ts.findValueRange(range, TimePeriodAnchor.MIDDLE, tzone).isNaNRange()); assertTrue(ts.findValueRange(range, TimePeriodAnchor.END, tzone).isNaNRange()); }
From source file:org.exoplatform.addon.pulse.service.ws.RestActivitiesStatistic.java
private ChartData buildPlfDownloadData(String maxColumn, String filter, Date fromDate) { int totalDataCoulumn = 5; try {// ww w. jav a 2 s .c om totalDataCoulumn = Integer.parseInt(maxColumn); } catch (Exception e) { //do nothing } if (filter.equalsIgnoreCase(FILTER_BY_DAY)) { List<String> listTitle = new ArrayList<String>(); List<Long> plfDownloadsData = new ArrayList<Long>(); for (int i = 0; i < totalDataCoulumn; i++) { Calendar calendar = Calendar.getInstance(); calendar.clear(); calendar.setTime(fromDate); calendar.add(Calendar.DATE, i); Date toDate = calendar.getTime(); String toDateStr = partString(toDate, "yyyy-MM-dd"); listTitle.add(partString(toDate, "dd-MM-yyyy")); String url = "http://sourceforge.net/projects/exo/files/stats/json?start_date=" + toDateStr + "&end_date=" + toDateStr; try { String returnValue = httpGet(url); plfDownloadsData.add(getTotalPlfDownloadDataFromJson(returnValue, toDate)); } catch (Exception e) { LOG.error(e.getMessage()); plfDownloadsData.add(0l); } } ChartData chartData = new ChartData(); chartData.setListTitle(listTitle); chartData.setPlfDownloadsData(plfDownloadsData); return chartData; } if (filter.equalsIgnoreCase(FILTER_BY_WEEK)) { List<String> listTitle = new ArrayList<String>(); List<Long> plfDownloadsData = new ArrayList<Long>(); String fromDateStr = partString(fromDate, "yyyy-MM-dd"); Calendar calendar = Calendar.getInstance(); calendar.clear(); calendar.setTime(fromDate); int fromWeek = calendar.get(Calendar.WEEK_OF_YEAR); int fromMonth = calendar.get(Calendar.MONTH); if (fromMonth == Calendar.DECEMBER && fromWeek == 1) fromWeek = 53; int fromYear = calendar.get(Calendar.YEAR); calendar.clear(); calendar.set(Calendar.WEEK_OF_YEAR, fromWeek); calendar.set(Calendar.YEAR, fromYear); Date beginWeekDate = calendar.getTime(); calendar.clear(); calendar.setTime(beginWeekDate); calendar.add(Calendar.DATE, 6); Date endWeekDate = calendar.getTime(); calendar.clear(); String toDateStr = partString(endWeekDate, "yyyy-MM-dd"); for (int i = 0; i < totalDataCoulumn; i++) { calendar.setTime(endWeekDate); listTitle.add("W" + calendar.get(Calendar.WEEK_OF_YEAR) + "-" + calendar.get(Calendar.YEAR)); String url = "http://sourceforge.net/projects/exo/files/stats/json?start_date=" + fromDateStr + "&end_date=" + toDateStr; try { String returnValue = httpGet(url); plfDownloadsData.add( getTotalPlfDownloadDataFromJson(returnValue, parseDate(fromDateStr, "yyyy-MM-dd"))); } catch (Exception e) { LOG.error(e.getMessage()); plfDownloadsData.add(0l); } calendar.clear(); fromDate = endWeekDate; calendar.setTime(fromDate); calendar.add(Calendar.DATE, 1); fromDate = calendar.getTime(); fromDateStr = partString(fromDate, "yyyy-MM-dd"); calendar.add(Calendar.DATE, 6); endWeekDate = calendar.getTime(); toDateStr = partString(endWeekDate, "yyyy-MM-dd"); calendar.clear(); } ChartData chartData = new ChartData(); chartData.setListTitle(listTitle); chartData.setPlfDownloadsData(plfDownloadsData); return chartData; } if (filter.equalsIgnoreCase(FILTER_BY_MONTH)) { List<String> listTitle = new ArrayList<String>(); List<Long> plfDownloadsData = new ArrayList<Long>(); String fromDateStr = partString(fromDate, "yyyy-MM-dd"); Calendar calendar = Calendar.getInstance(); calendar.clear(); calendar.setTime(fromDate); int fromMonth = calendar.get(Calendar.MONTH); int fromYear = calendar.get(Calendar.YEAR); //calendar.add(Calendar.MONTH, totalDataCoulumn); //int toYear = calendar.get(Calendar.YEAR); calendar.clear(); calendar.set(Calendar.MONTH, fromMonth); calendar.set(Calendar.YEAR, fromYear); Date beginMonthDate = calendar.getTime(); calendar.clear(); calendar.setTime(beginMonthDate); int dayOfMonth = calendar.getActualMaximum(Calendar.DAY_OF_MONTH); calendar.add(Calendar.DATE, dayOfMonth - 1); Date endMonthDate = calendar.getTime(); calendar.clear(); String toDateStr = partString(endMonthDate, "yyyy-MM-dd"); for (int i = 0; i < totalDataCoulumn; i++) { calendar.setTime(endMonthDate); listTitle.add(partString(calendar.getTime(), "MMM") + "-" + calendar.get(Calendar.YEAR)); String url = "http://sourceforge.net/projects/exo/files/stats/json?start_date=" + fromDateStr + "&end_date=" + toDateStr; try { String returnValue = httpGet(url); plfDownloadsData.add( getTotalPlfDownloadDataFromJson(returnValue, parseDate(fromDateStr, "yyyy-MM-dd"))); } catch (Exception e) { plfDownloadsData.add(0l); } calendar.clear(); fromDate = endMonthDate; calendar.setTime(fromDate); calendar.add(Calendar.DATE, 1); fromDate = calendar.getTime(); fromDateStr = partString(fromDate, "yyyy-MM-dd"); dayOfMonth = calendar.getActualMaximum(Calendar.DAY_OF_MONTH); calendar.add(Calendar.DATE, dayOfMonth - 1); endMonthDate = calendar.getTime(); toDateStr = partString(endMonthDate, "yyyy-MM-dd"); calendar.clear(); } ChartData chartData = new ChartData(); chartData.setListTitle(listTitle); chartData.setPlfDownloadsData(plfDownloadsData); return chartData; } return null; }
From source file:com.square.adherent.noyau.service.implementations.ContratServiceImpl.java
@Override public ContratSimpleDto getContratSantePersonne(Long idPersonne) { logger.debug(messageSourceUtil.get(MessageKeyUtil.LOGGER_DEBUG_RECUP_CONTRAT_SANTE_PERSONNE, new String[] { String.valueOf(idPersonne) })); // On recherche le contrat en cours de la personne Contrat contrat = contratDao.getContratSantePersonneEnCours(idPersonne); // Si la personne n'a aucun contrat en cours, on recherche un contrat rsili dans un dlai de X mois if (contrat == null) { final Calendar dateInactivite = Calendar.getInstance(); final int jour = dateInactivite.get(Calendar.DAY_OF_MONTH); final int mois = dateInactivite.get(Calendar.MONTH); final int annee = dateInactivite.get(Calendar.YEAR); dateInactivite.clear(); dateInactivite.set(annee, mois, jour); dateInactivite.add(Calendar.MONTH, -delaiMoisInactiviteGarantieSante); contrat = contratDao.getContratSantePersonneInactifXMois(idPersonne, dateInactivite); }/*from ww w . ja v a 2 s . co m*/ // Si la personne n'a aucun contrat en cours et aucun contrat rsili if (contrat == null) { // On recherche un contrat venir pour cette personne contrat = contratDao.getContratSantePersonneAVenir(idPersonne); } return mapperDozerBean.map(contrat, ContratSimpleDto.class); }
From source file:com.continuent.tungsten.common.mysql.MySQLPacket.java
/** * Puts a {@link Date} to the buffer as:<br> * two bytes year one byte month one byte day * /*from ww w .j a va 2 s . c o m*/ * @param d jdbc date to write * @return the rounded date as milliseconds actually put (without hh mm ss * ms information) */ public long putDate(Date d) { Calendar fullDate = new GregorianCalendar(); fullDate.clear(); fullDate.setTimeInMillis(d.getTime()); // MYO-100: We need to return the remaining millis for the date only, // not for its HHMMSSMS Calendar yymmddOnly = new GregorianCalendar(fullDate.get(Calendar.YEAR), fullDate.get(Calendar.MONTH), fullDate.get(Calendar.DAY_OF_MONTH)); // Note: Supported range for MySQL date is '1000-01-01' to '9999-12-31'. // So we don't care about era field (BC/AD) putInt16(yymmddOnly.get(Calendar.YEAR)); // 1-based (ie. 1 for January) putByte((byte) (1 + yymmddOnly.get(Calendar.MONTH))); // 1-based (ie. 1 for 1st of the month) putByte((byte) yymmddOnly.get(Calendar.DAY_OF_MONTH)); return yymmddOnly.getTimeInMillis(); }
From source file:org.apache.flume.sink.hdfs.TestHDFSEventSink.java
@Test public void testSlowAppendFailure() throws InterruptedException, LifecycleException, EventDeliveryException, IOException { LOG.debug("Starting..."); final String fileName = "FlumeData"; final long rollCount = 5; final long batchSize = 2; final int numBatches = 2; String newPath = testPath + "/singleBucket"; int i = 1, j = 1; // clear the test directory Configuration conf = new Configuration(); FileSystem fs = FileSystem.get(conf); Path dirPath = new Path(newPath); fs.delete(dirPath, true);// w w w. j a v a 2s . c om fs.mkdirs(dirPath); // create HDFS sink with slow writer HDFSBadWriterFactory badWriterFactory = new HDFSBadWriterFactory(); sink = new HDFSEventSink(badWriterFactory); Context context = new Context(); context.put("hdfs.path", newPath); context.put("hdfs.filePrefix", fileName); context.put("hdfs.rollCount", String.valueOf(rollCount)); context.put("hdfs.batchSize", String.valueOf(batchSize)); context.put("hdfs.fileType", HDFSBadWriterFactory.BadSequenceFileType); context.put("hdfs.callTimeout", Long.toString(1000)); Configurables.configure(sink, context); Channel channel = new MemoryChannel(); Configurables.configure(channel, context); sink.setChannel(channel); sink.start(); Calendar eventDate = Calendar.getInstance(); // push the event batches into channel for (i = 0; i < numBatches; i++) { Transaction txn = channel.getTransaction(); txn.begin(); for (j = 1; j <= batchSize; j++) { Event event = new SimpleEvent(); eventDate.clear(); eventDate.set(2011, i, i, i, 0); // yy mm dd event.getHeaders().put("timestamp", String.valueOf(eventDate.getTimeInMillis())); event.getHeaders().put("hostname", "Host" + i); event.getHeaders().put("slow", "1500"); event.setBody(("Test." + i + "." + j).getBytes()); channel.put(event); } txn.commit(); txn.close(); // execute sink to process the events Status satus = sink.process(); // verify that the append returned backoff due to timeotu Assert.assertEquals(satus, Status.BACKOFF); } sink.stop(); }
From source file:ypcnv.views.impl.FileVCF.java
@SuppressWarnings("unused") private void setBirthday(Contact2k3 contact, VCard vCard, String key) throws FileViewException { String value = (String) contact.getFieldValue(key); if (!value.isEmpty()) { // XXX - Here is a bug with date format and XLS cell content. // XXX - Try to convert in XLS file cell's into "text". //SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String dateFormatString = "d.M.y"; SimpleDateFormat dateFormat = new SimpleDateFormat(dateFormatString); Date date = null;//from w w w . j a va 2 s .c o m try { date = dateFormat.parse(value); } catch (ParseException e) { LOG.error( String.format( "Failed with date parsing, wanted format is '" + dateFormatString + "'. Input value is '%s'" + " from field '%s'. Problem caused with: %s", value, key, contact.toString())); e.printStackTrace(); return; } Calendar birthday = Calendar.getInstance(); birthday.clear(); birthday.setTime(date); // birthday.set(Calendar.YEAR, 1001); // birthday.set(Calendar.MONTH, 1); // birthday.set(Calendar.DAY_OF_MONTH, 1); vCard.setBirthday(new BirthdayType(birthday)); } }