List of usage examples for org.joda.time.format DateTimeFormat forPattern
public static DateTimeFormatter forPattern(String pattern)
From source file:com.dataartisans.timeoutmonitoring.TimestampExtractorFunction.java
License:Apache License
public TimestampExtractorFunction(String timestampField, String pattern) { this.timestampField = timestampField; this.pattern = pattern; formatter = DateTimeFormat.forPattern(pattern); }
From source file:com.dataartisans.timeoutmonitoring.TimestampExtractorFunction.java
License:Apache License
private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException { ois.defaultReadObject();//from ww w . j a va2 s .c o m formatter = DateTimeFormat.forPattern(pattern); }
From source file:com.datasalt.pangool.examples.movingaverage.MovingAverageGenerateData.java
License:Apache License
public final static void main(String[] args) throws IOException { if (args.length != 3) { System.err.println();/*from w w w . j av a 2 s . co m*/ System.err.println("Three arguments are needed."); System.err.println("Usage: [out-file] [nRegisters] [nUrls]"); System.err.println(); System.err.println( "Example: url_regs.txt 10 2 -> Will generate a file 'url_regs.txt' with 10 registers from 2 different urls."); System.err.println(); System.exit(-1); } String outFile = args[0]; int nRegisters = Integer.parseInt(args[1]); int nUrls = Integer.parseInt(args[2]); DateTimeFormatter format = DateTimeFormat.forPattern("yyyy-MM-dd"); long now = System.currentTimeMillis(); BufferedWriter writer = new BufferedWriter(new FileWriter(outFile)); for (int i = 0; i < nRegisters; i++) { int urlId = (int) (Math.random() * nUrls); int randomCount = (int) (Math.random() * 10000); writer.write("url" + urlId + "\t" + format.print(now) + "\t" + randomCount + "\n"); now -= 1000 * 60 * 60 * 24; } writer.close(); }
From source file:com.davis.bluefolder.BlueUtils.java
public static String contructDatesForSearch(String start, String end) { DateTimeFormatter fmt = DateTimeFormat.forPattern("MM-dd-yyyy hh:mma"); DateTimeZone timeZone = DateTimeZone.forID("America/New_York"); // Specify or else the JVM's default will apply. DateTime dateTime = new DateTime(new java.util.Date(), timeZone); // Today's Date DateTime pastDate = dateTime.minusDays(14); // 2 weeks ago String endDate = null;//from w w w. ja va 2 s.c om String startDate = null; if (start != null && !start.trim().equalsIgnoreCase("")) { if (end != null && !end.trim().equalsIgnoreCase("")) { startDate = fmt.parseDateTime(start).toString(); endDate = fmt.parseDateTime(end).toString(); } else { endDate = fmt.print(dateTime); startDate = fmt.print(pastDate); } } else { endDate = fmt.print(dateTime); startDate = fmt.print(pastDate); } //dateTimeClosed String date = " <dateRange dateField=\"dateTimeCreated\">" + "<startDate>" + startDate + "</startDate>" + "<endDate>" + endDate + "</endDate>" + "</dateRange>"; return date; }
From source file:com.dmrr.asistenciasx.Clock.java
public Clock(JLabel label, String format) { Jlabel = label;/*from www. j ava 2s.c o m*/ dateFormat = format; final ScheduledExecutorService service = Executors.newSingleThreadScheduledExecutor(); Runnable updateClock = new Runnable() { long thisTimer = 0; Calendar calendar = Calendar.getInstance(); DateTime jodaTime; DateTimeFormatter formatter = DateTimeFormat.forPattern(dateFormat); @Override public void run() { jodaTime = new DateTime(); Jlabel.setText(jodaTime.toString(formatter)); } }; service.scheduleWithFixedDelay(updateClock, 1, 1, TimeUnit.SECONDS); }
From source file:com.dmrr.asistenciasx.VentanaDeAsistenciaDeProfesor.java
private boolean yaSeRegistroAsistencia() { dateTime = new DateTime(); Integer minuto = Integer.parseInt(dateTime.toString(DateTimeFormat.forPattern("m"))); String fechayhora;/*from ww w . ja v a 2 s .c o m*/ if (minuto >= 45) { dateTime = dateTime.plusHours(1); fechayhora = dateTime.toString(DateTimeFormat.forPattern("yyyy-MM-dd HH:00:00")); dateTime = dateTime.minusHours(1); } else { fechayhora = dateTime.toString(DateTimeFormat.forPattern("yyyy-MM-dd HH:00:00")); } Query yaSeRegistro = em.createNativeQuery("SELECT * FROM registrodeasistencias WHERE idprofesor = " + profesor.getIdprofesor() + " AND fechayhora BETWEEN '" + fechayhora + "' - INTERVAL 15 MINUTE AND '" + fechayhora + "' + INTERVAL 15 MINUTE"); try { Object x = yaSeRegistro.getSingleResult(); return true; } catch (javax.persistence.NoResultException e) { return false; } catch (javax.persistence.NonUniqueResultException ex) { return true; } }
From source file:com.DSC.client.SecureChannel.java
License:Open Source License
/** * @param args//from w ww. j a v a2 s . c om * @throws InterruptedException * @throws IOException */ public static void main(String[] args) throws InterruptedException, IOException { /* Create their private & public keys */ ECKey key = new ECKey(); key.init(); ProgramState.publicKey = (ECPublicKeyParameters) key.getPublic(); ProgramState.privateKey = (ECPrivateKeyParameters) key.getPrivate(); /* Create the IV engine */ byte[] seed = new byte[64]; // 512 bit seed SecureRandom random = new SecureRandom(); random.nextBytes(seed); ProgramState.IVEngine = new ISAACRandomGenerator(new ISAACEngine()); ProgramState.IVEngine.init(seed); /* Create the blacklist and trusted contacts */ ProgramState.blacklist = ConcurrentHashMultiset.create(); ProgramState.trustedKeys = new ConcurrentHashMap<String, Address>(); /* Set the time for the client accurately using a NTP server */ DateTimeUtils.setCurrentMillisOffset(getTimeOffset()); ProgramState.fmt = DateTimeFormat.forPattern("HH:mm:ss"); /* Set the default nick as anonymous */ ProgramState.nick = "anonymous"; /* Initialize ISAACRandomGenerator, set ProgramState.IVEngine */ receiveController = new ReceiveController(); sendController = new SendController(); /* Start input event handler loop */ eventLoop(); }
From source file:com.dtstack.jlogstash.date.FormatParser.java
License:Apache License
public FormatParser(String format, String timezone, String locale) { this.formatter = DateTimeFormat.forPattern(format); if (timezone != null) { this.formatter = this.formatter.withZone(DateTimeZone.forID(timezone)); } else {//from w w w . jav a 2 s.c o m this.formatter = this.formatter.withOffsetParsed(); } if (locale != null) { this.formatter = this.formatter.withLocale(Locale.forLanguageTag(locale)); } }
From source file:com.dtstack.jlogstash.render.Formatter.java
License:Apache License
public static String format(Map event, String format, String Timezone) { Matcher m = p.matcher(format); StringBuffer sb = new StringBuffer(); while (m.find()) { String match = m.group(); String key = (String) match.subSequence(2, match.length() - 1); if (key.equalsIgnoreCase("+s")) { Object o = event.get("@timestamp"); if (o.getClass() == Long.class) { m.appendReplacement(sb, o.toString()); }//www . j a v a2s . c om } else if (key.startsWith("+")) { DateTimeFormatter formatter = DateTimeFormat.forPattern((String) key.subSequence(1, key.length())) .withZone(DateTimeZone.forID(Timezone)); Object o = event.get("@timestamp"); if (o == null) { DateTime timestamp = new DateTime(); m.appendReplacement(sb, timestamp.toString(formatter)); } else { if (o.getClass() == DateTime.class) { m.appendReplacement(sb, ((DateTime) o).toString(formatter)); } else if (o.getClass() == Long.class) { DateTime timestamp = new DateTime((Long) o); m.appendReplacement(sb, timestamp.toString(formatter)); } else if (o.getClass() == String.class) { DateTime timestamp = ISOformatter.parseDateTime((String) o); m.appendReplacement(sb, timestamp.toString(formatter)); } } } else if (event.containsKey(key)) { m.appendReplacement(sb, event.get(key).toString()); } } m.appendTail(sb); return sb.toString(); }
From source file:com.ecofactor.qa.automation.util.DateUtil.java
License:Open Source License
/** * Gets the current time stamp./*from w w w . j ava2 s . c o m*/ * @return the current time stamp */ public static String getUTCCurrentTimeStamp() { DateTime startDate = new DateTime(DateTimeZone.UTC); DateTimeFormatter fmt = DateTimeFormat.forPattern(DATE_FMT_FULL); return fmt.print(startDate); }