List of usage examples for java.util Date setTime
public void setTime(long time)
From source file:jef.tools.DateUtils.java
/** * //from w ww .j a v a 2 s . c om */ public static void addDay(Date d, int value) { d.setTime(d.getTime() + value * TimeUnit.DAY.ms); }
From source file:jef.tools.DateUtils.java
/** * /* w w w . j a va 2s. com*/ */ public static void addMillSec(Date d, long value) { d.setTime(d.getTime() + value); }
From source file:jef.tools.DateUtils.java
/** * /*from ww w . j a v a 2s.c om*/ */ public static void addSec(Date d, long value) { d.setTime(d.getTime() + value * TimeUnit.SECOND.ms); }
From source file:org.nodatime.tzvalidate.IcuDump.java
@Override public ZoneTransitions getTransitions(String id, int fromYear, int toYear) { BasicTimeZone zone = (BasicTimeZone) TimeZone.getTimeZone(id); // A poor attempt to get the time zone abbreviation. It's // locale-sensitive, and then only // applies some of the time. // See http://stackoverflow.com/questions/31626356 DateFormat nameFormat = new SimpleDateFormat("zzz", Locale.US); nameFormat.setTimeZone(zone);/*from w w w . j a v a 2s . c o m*/ Calendar calendar = GregorianCalendar.getInstance(UTC); calendar.set(fromYear, 0, 1, 0, 0, 0); calendar.set(Calendar.MILLISECOND, 0); long start = calendar.getTimeInMillis(); calendar.set(toYear, 0, 1, 0, 0, 0); long end = calendar.getTimeInMillis(); Date date = new Date(start); ZoneTransitions transitions = new ZoneTransitions(id); transitions.addTransition(null, zone.getOffset(start), zone.inDaylightTime(date), nameFormat.format(date)); TimeZoneTransition transition = zone.getNextTransition(start, true /* inclusive */); while (transition != null && transition.getTime() < end) { long now = transition.getTime(); date.setTime(now); transitions.addTransition(date, zone.getOffset(now), zone.inDaylightTime(date), nameFormat.format(date)); transition = zone.getNextTransition(now, false /* exclusive */); } return transitions; }
From source file:com.hihframework.core.utils.DateUtils.java
public static void setDateParameter(java.sql.Date date, int param, int value) { if (date == null) { return;/*from ww w . j a v a2 s .c o m*/ } cal.setTime(new java.util.Date(date.getTime())); cal.set(param, value); date.setTime(cal.getTime().getTime()); }
From source file:jef.tools.DateUtils.java
/** * ?/*from w ww .j av a 2 s . co m*/ * * @param date * @return ?1 */ public static final Date monthEnd(Date date) { if (date == null) return null; Calendar calendar = Calendar.getInstance(); calendar.setTime(date); calendar.set(Calendar.DATE, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));// ? calendar = org.apache.commons.lang.time.DateUtils.truncate(calendar, Calendar.DATE);// Date d = calendar.getTime(); d.setTime(d.getTime() + MILLISECONDS_IN_DAY - 1); // ?1 return d; }
From source file:py.una.pol.karaku.dao.where.DateClauses.java
@Nonnull private Date addMinute(@Nonnull Date date, int minutes) { date.setTime(date.getTime() + MILISECOND_SECOND * minutes); return date;//from www . java2s .co m }
From source file:org.guanxi.idp.Bootstrap.java
public boolean createSelfSignedKeystore(String cn, String keystoreFile, String keystorePassword, String privateKeyPassword, String privateKeyAlias) { KeyStore ks = null;//from ww w.j a v a 2 s .c o m try { ks = KeyStore.getInstance("JKS"); ks.load(null, null); KeyPairGenerator keyGen = KeyPairGenerator.getInstance("DSA"); keyGen.initialize(1024, new SecureRandom()); KeyPair keypair = keyGen.generateKeyPair(); PrivateKey privkey = keypair.getPrivate(); PublicKey pubkey = keypair.getPublic(); Hashtable<DERObjectIdentifier, String> attrs = new Hashtable<DERObjectIdentifier, String>(); Vector<DERObjectIdentifier> ordering = new Vector<DERObjectIdentifier>(); ordering.add(X509Name.CN); attrs.put(X509Name.CN, cn); X509Name issuerDN = new X509Name(ordering, attrs); X509Name subjectDN = new X509Name(ordering, attrs); Date validFrom = new Date(); validFrom.setTime(validFrom.getTime() - (10 * 60 * 1000)); Date validTo = new Date(); validTo.setTime(validTo.getTime() + (20 * (24 * 60 * 60 * 1000))); X509V3CertificateGenerator x509 = new X509V3CertificateGenerator(); x509.setSignatureAlgorithm("SHA1withDSA"); x509.setIssuerDN(issuerDN); x509.setSubjectDN(subjectDN); x509.setPublicKey(pubkey); x509.setNotBefore(validFrom); x509.setNotAfter(validTo); x509.setSerialNumber(new BigInteger(128, new Random())); X509Certificate[] cert = new X509Certificate[1]; cert[0] = x509.generate(privkey, "BC"); java.security.cert.Certificate[] chain = new java.security.cert.Certificate[1]; chain[0] = cert[0]; ks.setKeyEntry(privateKeyAlias, privkey, privateKeyPassword.toCharArray(), cert); ks.setKeyEntry(privateKeyAlias, privkey, privateKeyPassword.toCharArray(), chain); ks.store(new FileOutputStream(keystoreFile), keystorePassword.toCharArray()); String IDP_RFC_CERT = "WEB-INF/guanxi_idp/keystore/guanxi_idp_cert.txt"; PEMWriter pemWriter = new PEMWriter(new FileWriter(servletContext.getRealPath(IDP_RFC_CERT))); pemWriter.writeObject(cert[0]); pemWriter.close(); return true; } catch (Exception se) { return false; } }
From source file:org.teleportr.plugin.BahnDePlugIn.java
private Date parseDate(String hours, String minutes) { Date date = new Date(); date.setHours(Integer.parseInt(hours)); date.setMinutes(Integer.parseInt(minutes)); date.setSeconds(0);/*from ww w . j av a 2s . co m*/ //date.setTime((date.getTime() / 1000) * 1000); if (System.currentTimeMillis() - date.getTime() > 300000) { // Mitternacht.. long oneDay = (long) 1000.0 * 60 * 60 * 24; date.setTime(date.getTime() + oneDay); } return date; }
From source file:org.fcrepo.legacy.FedoraDatastreams.java
/** * Get the binary content of a datastream * //from w w w. j ava2 s .com * @param pid persistent identifier of the digital object * @param dsid datastream identifier * @return Binary blob * @throws RepositoryException */ @GET @Path("/{dsid}/content") public Response getDatastreamContent(@PathParam("pid") final String pid, @PathParam("dsid") final String dsid, @Context final Request request) throws RepositoryException { try { final Datastream ds = datastreamService.getDatastream(session, LegacyPathHelpers.getDatastreamsPath(pid, dsid)); final EntityTag etag = new EntityTag(ds.getContentDigest().toString()); final Date date = ds.getLastModifiedDate(); final Date roundedDate = new Date(); roundedDate.setTime(date.getTime() - date.getTime() % 1000); ResponseBuilder builder = request.evaluatePreconditions(roundedDate, etag); final CacheControl cc = new CacheControl(); cc.setMaxAge(0); cc.setMustRevalidate(true); if (builder == null) { builder = Response.ok(ds.getContent(), ds.getMimeType()); } return builder.cacheControl(cc).lastModified(date).tag(etag).build(); } finally { session.logout(); } }