Java Code Examples for java.util.Date
The following code examples are extracted from open source projects. You can click to
vote up the examples that are useful to you.
Example 1
From project 3Dto2DApplet, under directory /src/java/nl/dannyarends/generic/.
Source file: Utils.java

public static void log(String message,PrintStream out){ Date date=new Date(); out.println("[" + date.toString() + "] "+ message); if (guireporter != null) { guireporter.setText("[" + date.toString() + "] "+ message+ "\n"+ guireporter.getText()); } }
Example 2
From project activiti-webapp-rest-generic, under directory /activiti-webapp-rest/src/main/java/org/activiti/rest/api/cycle/.
Source file: CommentPost.java

@Override void execute(ActivitiRequest req,Status status,Cache cache,Map<String,Object> model){ ActivitiRequestObject obj=req.getBody(); String connectorId=req.getMandatoryString(obj,"connectorId"); String nodeId=req.getMandatoryString(obj,"nodeId"); String content=req.getMandatoryString(obj,"content"); String elementId=req.getOptionalString(obj,"elementId"); String answeredCommentId=req.getOptionalString(obj,"answeredCommentId"); String author=req.getCurrentUserId(); Date date=new Date(); this.commentService.insertComment(connectorId,nodeId,elementId,content,author,date,answeredCommentId); }
Example 3
From project Absolute-Android-RSS, under directory /src/com/AA/Other/.
Source file: DateFunctions.java

/** * Creates a Calendar object based off a string with this format <Day name:3 letters>, DD <Month name: 3 letters> YYYY HH:MM:SS +0000 * @param date - The string we are to convert to a calendar date * @return - The calendar date object that this string represents */ public static Calendar makeDate(String date){ Date d=null; Calendar calendar=Calendar.getInstance(); try { SimpleDateFormat format=new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z"); d=format.parse(date); calendar.setTime(d); } catch ( ParseException e) { e.printStackTrace(); } return calendar; }
Example 4
From project addis, under directory /application/src/main/java/org/drugis/addis/imports/.
Source file: ClinicaltrialsImporter.java

private static Date guessDate(DateStruct startDate2){ Date startDate=null; SimpleDateFormat sdf=new SimpleDateFormat("MMM yyyy"); try { if (startDate2 != null) startDate=sdf.parse(startDate2.getContent()); } catch ( ParseException e) { System.err.println("ClinicalTrialsImporter:: Couldn't parse date. Left empty."); } return startDate; }
Example 5
From project acceleo-modules, under directory /psm-gen-scala/plugins/com.github.sbegaudeau.acceleo.modules.psm.gen.scala/src/com/github/sbegaudeau/acceleo/modules/psm/gen/scala/services/.
Source file: CommonServices.java

/** * Get the date in a long format : January 12, 1952 * @return String representing the long format date */ public static String genLongDate(){ Date date=new Date(); Locale locale=Locale.getDefault(); DateFormat dateFormatShort=DateFormat.getDateInstance(DateFormat.LONG,locale); return dateFormatShort.format(date); }
Example 6
From project accesointeligente, under directory /src/org/accesointeligente/client/.
Source file: ClientSessionUtil.java

public static void createSession(SessionData sessionData){ ClientSessionUtil.sessionData=sessionData; Cookies.removeCookie("sessionId","/"); final long cookieDuration=1000 * 60 * 24; Date expires=new Date(System.currentTimeMillis() + cookieDuration); Cookies.setCookie("sessionId",(String)sessionData.getData().get("sessionId"),expires,null,"/",false); }
Example 7
From project activiti-explorer, under directory /src/main/java/org/activiti/explorer/ui/form/.
Source file: DateFormPropertyRenderer.java

@Override public String getFieldValue(FormProperty formProperty,Field field){ PopupDateField dateField=(PopupDateField)field; Date selectedDate=(Date)dateField.getValue(); if (selectedDate != null) { String datePattern=(String)formProperty.getType().getInformation("datePattern"); SimpleDateFormat dateFormat=new SimpleDateFormat(datePattern); return dateFormat.format(selectedDate); } return null; }
Example 8
/** * Get the real time from the server * @author Lathanael * @param gmt The wanted GMT offset * @return serverTime Represents the time read from the server */ public static Date getServerRealTime(final String gmt){ Date serverTime; final TimeZone tz=TimeZone.getTimeZone(gmt); final Calendar cal=Calendar.getInstance(tz); cal.setTime(new Date()); serverTime=cal.getTime(); return serverTime; }
Example 9
From project AdServing, under directory /modules/db/src/main/java/test/ad/date/.
Source file: DateParse.java

public static void main(String[] args) throws Exception { SimpleDateFormat df=new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss"); Date d=df.parse("2010.06.25.08.36.33"); System.out.println(DateTools.dateToString(d,Resolution.SECOND)); System.out.println(DateTools.stringToDate(DateTools.dateToString(d,Resolution.SECOND)).toString()); System.out.println(d.toString()); System.out.println(new Date().toString()); }
Example 10
From project aether-core, under directory /aether-impl/src/test/java/org/eclipse/aether/internal/impl/.
Source file: DefaultUpdateCheckManagerTest.java

@Test public void testCheckMetadataNoLocalFile() throws Exception { metadata.getFile().delete(); UpdateCheck<Metadata,MetadataTransferException> check=newMetadataCheck(); long lastUpdate=new Date().getTime() - HOUR; check.setLocalLastUpdated(lastUpdate); check.setLocalLastUpdated(lastUpdate); manager.checkMetadata(session,check); assertEquals(true,check.isRequired()); }
Example 11
From project agile, under directory /agile-apps/agile-app-docs/src/main/java/org/headsupdev/agile/app/docs/.
Source file: CreateComment.java

public void onSubmit(){ getDocument(); submitChild(); Date now=new Date(); if (create.getComment() != null) { create.setUser(CreateComment.this.getSession().getUser()); create.setCreated(now); ((HibernateStorage)getStorage()).save(create); doc.getComments().add(create); } doc.setUpdated(now); getHeadsUpApplication().addEvent(getUpdateEvent(create)); setResponsePage(getPageClass("docs/"),getPageParameters()); }
Example 12
From project 2Degrees-Toolbox, under directory /Toolbox/src/biz/shadowservices/DegreesToolbox/.
Source file: AbstractWidgetUpdater.java

public String getUpdateDateString(Context context){ SharedPreferences sp=PreferenceManager.getDefaultSharedPreferences(context); if (sp.getBoolean("last_update_shown",true)) { String updateDateString=sp.getString("updateDate",""); try { Date now=new Date(); Date lastUpdate=DateFormatters.ISO8601FORMAT.parse(updateDateString); if (DateFormatters.isSameDay(now,lastUpdate)) { return DateFormatters.LASTUPDATETIME.format(lastUpdate); } else { return DateFormatters.LASTUPDATEDATE.format(lastUpdate); } } catch ( Exception e) { Log.d(TAG,e.getMessage()); return ""; } } else { return ""; } }
Example 13
From project activiti, under directory /src/activiti-examples/org/activiti/examples/bpmn/mail/.
Source file: EmailSendTaskTest.java

@Deployment @Test public void testSendEmail() throws Exception { String from="ordershipping@activiti.org"; boolean male=true; String recipientName="John Doe"; String recipient="johndoe@alfresco.com"; Date now=new Date(); String orderId="123456"; Map<String,Object> vars=new HashMap<String,Object>(); vars.put("sender",from); vars.put("recipient",recipient); vars.put("recipientName",recipientName); vars.put("male",male); vars.put("now",now); vars.put("orderId",orderId); RuntimeService runtimeService=activitiRule.getRuntimeService(); runtimeService.startProcessInstanceByKey("sendMailExample",vars); List<WiserMessage> messages=wiser.getMessages(); assertEquals(1,messages.size()); WiserMessage message=messages.get(0); MimeMessage mimeMessage=message.getMimeMessage(); assertEquals("Your order " + orderId + " has been shipped",mimeMessage.getHeader("Subject",null)); assertEquals("\"" + from + "\" <"+ from.toString()+ ">",mimeMessage.getHeader("From",null)); assertTrue(mimeMessage.getHeader("To",null).contains(recipient)); }
Example 14
From project Activiti-KickStart, under directory /activiti-kickstart-java/src/main/java/org/activiti/kickstart/service/.
Source file: TransformationServiceImpl.java

public List<KickstartWorkflowInfo> convertToWorkflowInfoList(List<ProcessDefinition> processDefinitions,boolean includeCounts){ List<KickstartWorkflowInfo> infoList=new ArrayList<KickstartWorkflowInfo>(); for ( ProcessDefinition processDefinition : processDefinitions) { KickstartWorkflowInfo workflowInfo=new KickstartWorkflowInfo(); workflowInfo.setId(processDefinition.getId()); workflowInfo.setKey(processDefinition.getKey()); workflowInfo.setName(processDefinition.getName()); workflowInfo.setVersion(processDefinition.getVersion()); workflowInfo.setDeploymentId(processDefinition.getDeploymentId()); Date deploymentTime=repositoryService.createDeploymentQuery().deploymentId(processDefinition.getDeploymentId()).singleResult().getDeploymentTime(); workflowInfo.setCreateTime(deploymentTime); if (includeCounts) { workflowInfo.setNrOfRuntimeInstances(historyService.createHistoricProcessInstanceQuery().processDefinitionId(processDefinition.getId()).unfinished().count()); workflowInfo.setNrOfHistoricInstances(historyService.createHistoricProcessInstanceQuery().processDefinitionId(processDefinition.getId()).finished().count()); } infoList.add(workflowInfo); } return infoList; }
Example 15
From project AdminStuff, under directory /src/main/java/de/minestar/AdminStuff/commands/.
Source file: cmdBan.java

private void ban(CommandSender sender,String playerName,String reason){ BanEntry banEntry=new BanEntry(playerName); banEntry.setCreated(new Date()); banEntry.setSource(sender.getName()); banEntry.setReason(reason); ((CraftServer)Bukkit.getServer()).getHandle().getNameBans().add(banEntry); }
Example 16
From project agileBase, under directory /gtpb_server/src/com/gtwm/pb/model/manageData/.
Source file: DataManagement.java

/** * Based on http://www.vogella.de/articles/RSSFeed/article.html */ private String generateRSS(AppUserInfo user,BaseReportInfo report,List<DataRowInfo> reportDataRows) throws XMLStreamException, ObjectNotFoundException { XMLOutputFactory outputFactory=XMLOutputFactory.newInstance(); StringWriter stringWriter=new StringWriter(); XMLEventWriter eventWriter=outputFactory.createXMLEventWriter(stringWriter); XMLEventFactory eventFactory=XMLEventFactory.newInstance(); XMLEvent end=eventFactory.createDTD("\n"); StartDocument startDocument=eventFactory.createStartDocument(); eventWriter.add(startDocument); eventWriter.add(end); StartElement rssStart=eventFactory.createStartElement("","","rss"); eventWriter.add(rssStart); eventWriter.add(eventFactory.createAttribute("version","2.0")); eventWriter.add(end); eventWriter.add(eventFactory.createStartElement("","","channel")); eventWriter.add(end); this.createNode(eventWriter,"title",report.getModule().getModuleName() + " - " + report.getReportName()); String reportLink="https://appserver.gtportalbase.com/agileBase/AppController.servlet?return=gui/display_application&set_table=" + report.getParentTable().getInternalTableName() + "&set_report="+ report.getInternalReportName(); this.createNode(eventWriter,"link",reportLink); this.createNode(eventWriter,"description","A live data feed from www.agilebase.co.uk"); DateFormat dateFormatter=new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z"); Date lastDataChangeDate=new Date(getLastCompanyDataChangeTime(user.getCompany())); this.createNode(eventWriter,"pubdate",dateFormatter.format(lastDataChangeDate)); for ( DataRowInfo reportDataRow : reportDataRows) { eventWriter.add(eventFactory.createStartElement("","","item")); eventWriter.add(end); this.createNode(eventWriter,"title",buildEventTitle(report,reportDataRow,false)); this.createNode(eventWriter,"description",reportDataRow.toString()); String rowLink=reportLink + "&set_row_id=" + reportDataRow.getRowId(); this.createNode(eventWriter,"link",rowLink); this.createNode(eventWriter,"guid",rowLink); eventWriter.add(end); eventWriter.add(eventFactory.createEndElement("","","item")); eventWriter.add(end); } eventWriter.add(eventFactory.createEndElement("","","channel")); eventWriter.add(end); eventWriter.add(eventFactory.createEndElement("","","rss")); eventWriter.add(end); return stringWriter.toString(); }
Example 17
From project agorava-facebook, under directory /agorava-facebook-api/src/main/java/org/agorava/facebook/model/.
Source file: FqlResult.java

/** * Returns the value of the identified field as a Date. Time fields returned from an FQL query are expressed in terms of seconds since midnight, January 1, 1970 UTC. * @param fieldName the name of the field * @return the value of the field as a Date * @throws FqlException if the field's value cannot be expressed as a long value from which a Date object can be constructed. */ public Date getTime(String fieldName){ try { long timeInMilliseconds=Long.valueOf(String.valueOf(resultMap.get(fieldName))) * 1000; return resultMap.containsKey(fieldName) ? new Date(timeInMilliseconds) : null; } catch ( NumberFormatException e) { throw new FqlException("Field '" + fieldName + "' is not a time.",e); } }
Example 18
From project agorava-twitter, under directory /agorava-twitter-api/src/main/java/org/agorava/twitter/model/.
Source file: RateLimitStatus.java

public RateLimitStatus(int hourlyLimit,int remainingHits,long resetTimeInSeconds){ this.hourlyLimit=hourlyLimit; this.remainingHits=remainingHits; this.resetTimeInSeconds=resetTimeInSeconds; this.resetTime=new Date(resetTimeInSeconds * 1000); }
Example 19
From project aio-webos, under directory /component/web/src/test/java/org/exoplatform/webos/services/desktop/test/.
Source file: TestDesktopBackgroundService.java

public void testGetUserDesktopBackground() throws Exception { desktopBackgroundService.uploadBackgroundImage(userName,imageName,mimeType,encoding,imgStream); DesktopBackground background=desktopBackgroundService.getUserDesktopBackground(userName,imageName); assertNotNull(background); assertEquals(imageName,background.getImageLabel()); background=desktopBackgroundService.getUserDesktopBackground(userName,imageName + new Date().getTime()); assertNull(background); background=desktopBackgroundService.getUserDesktopBackground(userName,null); assertNull(background); }
Example 20
From project AirCastingAndroidClient, under directory /src/main/java/pl/llp/aircasting/activity/.
Source file: MakeANoteActivity.java

@Override protected void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.make_a_note); date=new Date(); dateText.setText(FormatHelper.dateTime(date)); save.setOnClickListener(this); share.setOnClickListener(this); attachPhoto.setOnClickListener(this); }
Example 21
From project AChartEngine, under directory /achartengine/src/org/achartengine/chart/.
Source file: TimeChart.java

/** * The graphical representation of the labels on the X axis. * @param xLabels the X labels values * @param xTextLabelLocations the X text label locations * @param canvas the canvas to paint to * @param paint the paint to be used for drawing * @param left the left value of the labels area * @param top the top value of the labels area * @param bottom the bottom value of the labels area * @param xPixelsPerUnit the amount of pixels per one unit in the chart labels * @param minX the minimum value on the X axis in the chart * @param maxX the maximum value on the X axis in the chart */ @Override protected void drawXLabels(List<Double> xLabels,Double[] xTextLabelLocations,Canvas canvas,Paint paint,int left,int top,int bottom,double xPixelsPerUnit,double minX,double maxX){ int length=xLabels.size(); if (length > 0) { boolean showLabels=mRenderer.isShowLabels(); boolean showGridY=mRenderer.isShowGridY(); DateFormat format=getDateFormat(xLabels.get(0),xLabels.get(length - 1)); for (int i=0; i < length; i++) { long label=Math.round(xLabels.get(i)); float xLabel=(float)(left + xPixelsPerUnit * (label - minX)); if (showLabels) { paint.setColor(mRenderer.getXLabelsColor()); canvas.drawLine(xLabel,bottom,xLabel,bottom + mRenderer.getLabelsTextSize() / 3,paint); drawText(canvas,format.format(new Date(label)),xLabel,bottom + mRenderer.getLabelsTextSize() * 4 / 3,paint,mRenderer.getXLabelsAngle()); } if (showGridY) { paint.setColor(mRenderer.getGridColor()); canvas.drawLine(xLabel,bottom,xLabel,top,paint); } } } drawXTextLabels(xTextLabelLocations,canvas,paint,true,left,top,bottom,xPixelsPerUnit,minX,maxX); }
Example 22
From project ACLS-protocol-library, under directory /aclslib/src/main/java/au/edu/uq/cmm/aclslib/dummy/.
Source file: RequestProcessor.java

private void processLoginRequest(Request m,BufferedWriter w) throws AclsException { LoginRequest login=(LoginRequest)m; String timestamp=DateFormat.getInstance().format(new Date()); List<String> accounts=Arrays.asList("general","special"); Response r; if (!login.getPassword().equals("secret")) { r=new RefusedResponse(ResponseType.VIRTUAL_LOGIN_REFUSED); } else if (login.getUserName().equals("junior")) { r=new LoginResponse(ResponseType.VIRTUAL_LOGIN_ALLOWED,login.getUserName(),"CMMMM",timestamp,accounts,Certification.NONE,true); } else if (login.getUserName().equals("badboy")) { r=new LoginResponse(ResponseType.VIRTUAL_LOGIN_ALLOWED,login.getUserName(),"CMMMM",timestamp,accounts,Certification.NONE,false); } else { r=new LoginResponse(ResponseType.VIRTUAL_LOGIN_ALLOWED,login.getUserName(),"CMMMM",timestamp,accounts,Certification.VALID,false); } sendResponse(w,r); }
Example 23
From project activemq-apollo, under directory /apollo-util/src/main/scala/org/apache/activemq/apollo/util/tar/.
Source file: TarEntry.java

/** * Construct an entry with only a name. This allows the programmer to construct the entry's header "by hand". File is set to null. * @param name the entry name * @param preserveLeadingSlashes whether to allow leading slashesin the name. */ public TarEntry(String name,boolean preserveLeadingSlashes){ this(); name=normalizeFileName(name,preserveLeadingSlashes); boolean isDir=name.endsWith("/"); this.devMajor=0; this.devMinor=0; this.name=new StringBuffer(name); this.mode=isDir ? DEFAULT_DIR_MODE : DEFAULT_FILE_MODE; this.linkFlag=isDir ? LF_DIR : LF_NORMAL; this.userId=0; this.groupId=0; this.size=0; this.modTime=(new Date()).getTime() / MILLIS_PER_SECOND; this.linkName=new StringBuffer(""); this.userName=new StringBuffer(""); this.groupName=new StringBuffer(""); this.devMajor=0; this.devMinor=0; }
Example 24
From project activejdbc, under directory /javalite-common/src/main/java/org/javalite/common/.
Source file: Convert.java

/** * Expects a <code>java.sql.Date</code>, <code>java.sql.Timestamp</code>, <code>java.sql.Time</code>, <code>java.util.Date</code> or any object whose toString method has this format: <code>yyyy-mm-dd</code>. * @param value argument that is possible to convert to <code>java.sql.Date</code>. * @return <code>java.sql.Date</code> instance representing input value. */ public static java.sql.Date toSqlDate(Object value){ if (value == null) { return null; } else if (value instanceof java.sql.Date) { return (java.sql.Date)value; } else if (value instanceof Timestamp) { return new java.sql.Date(((Timestamp)value).getTime()); } else if (value instanceof java.util.Date) { return new java.sql.Date(((Date)value).getTime()); } else if (value instanceof Time) { return new java.sql.Date(((Time)value).getTime()); } else { try { return java.sql.Date.valueOf(value.toString()); } catch ( IllegalArgumentException e) { throw new ConversionException("failed to convert: '" + value + "' to java.sql.Date",e); } } }
Example 25
From project adbcj, under directory /api/src/main/java/org/adbcj/support/.
Source file: DefaultValue.java

public Date getDate(){ if (value == null) { return null; } if (value instanceof Date) { return (Date)value; } throw new DbException(String.format("%s is not a date",value.toString())); }
Example 26
From project adg-android, under directory /src/com/analysedesgeeks/android/utils/.
Source file: DateUtils.java

public Date parse(final String source) throws ParseException { if (source == null) { throw new ParseException("source is null",0); } return formater.parse(source); }
Example 27
From project agorava-linkedin, under directory /agorava-linkedin-api/src/main/java/org/agorava/linkedin/model/.
Source file: Comment.java

public Comment(String comment,String id,LinkedInProfile person,int sequenceNumber,Date timestamp){ this.comment=comment; this.id=id; this.person=person; this.sequenceNumber=sequenceNumber; this.timestamp=timestamp; }