List of usage examples for org.joda.time DateTime getYear
public int getYear()
From source file:org.jbpm.designer.web.server.SimulationServlet.java
License:Apache License
private String getDateString(long seDate) { Date d = new Date(seDate); DateTime dt = new DateTime(seDate); StringBuffer retBuf = new StringBuffer(); retBuf.append(dt.getYear()).append(","); retBuf.append(dt.getMonthOfYear()).append(","); retBuf.append(dt.getDayOfMonth()).append(","); retBuf.append(dt.getHourOfDay()).append(","); retBuf.append(dt.getMinuteOfHour()).append(","); retBuf.append(dt.getSecondOfMinute()).append(","); retBuf.append(dt.getMillisOfSecond()); return retBuf.toString(); }
From source file:org.jimcat.services.rename.Renamer.java
License:Open Source License
@SuppressWarnings("null") private String getNewName(Image image, int n) { String newName = configString; DateTime date = null; switch (useDate) { case MODIFICATION: date = image.getMetadata().getModificationDate(); break;//from w w w . j av a 2 s. c om case ADDED: date = image.getMetadata().getDateAdded(); break; case TAKEN: ExifMetadata exifMetadata = image.getExifMetadata(); if (exifMetadata != null) { date = exifMetadata.getDateTaken(); } break; } String random; do { random = String.valueOf(Math.random()); } while (configString.contains(random)); if (hasParameter(escapeCharacter.charAt(0))) { newName = newName.replace(escapeCharacter + escapeCharacter, random); } if (hasParameter('n')) { String number = String.format("%0" + digits + "d", new Integer(n)); newName = newName.replace(escapeCharacter + "n", number); } if (hasParameter('w')) { newName = newName.replace(escapeCharacter + "w", "" + image.getMetadata().getWidth()); } if (hasParameter('h')) { newName = newName.replace(escapeCharacter + "h", "" + image.getMetadata().getHeight()); } if (hasParameter('d')) { if (date == null) { newName = newName.replace(escapeCharacter + "d", unknownResultCharacter); } else { String day = formatNumber(date.getDayOfMonth(), 2); newName = newName.replace(escapeCharacter + "d", day); } } if (hasParameter('m')) { if (date == null) { newName = newName.replace(escapeCharacter + "m", unknownResultCharacter); } else { String month = formatNumber(date.getMonthOfYear(), 2); newName = newName.replace(escapeCharacter + "m", month); } } if (hasParameter('y')) { if (date == null) { newName = newName.replace(escapeCharacter + "y", unknownResultCharacter); } else { String year = formatNumber(date.getYear(), 4); newName = newName.replace(escapeCharacter + "y", year); } } if (hasParameter('H')) { if (date == null) { newName = newName.replace(escapeCharacter + "H", unknownResultCharacter); } else { String hour = formatNumber(date.getHourOfDay(), 2); newName = newName.replace(escapeCharacter + "H", hour); } } if (hasParameter('M')) { if (date == null) { newName = newName.replace(escapeCharacter + "M", unknownResultCharacter); } else { String minute = formatNumber(date.getMinuteOfHour(), 2); newName = newName.replace(escapeCharacter + "M", minute); } } if (hasParameter('S')) { if (date == null) { newName = newName.replace(escapeCharacter + "S", unknownResultCharacter); } else { String seconds = formatNumber(date.getSecondOfMinute(), 2); newName = newName.replace(escapeCharacter + "S", seconds); } } if (hasParameter('r')) { newName = newName.replace(escapeCharacter + "r", ratingToString(image.getRating())); } if (hasParameter('f')) { if (image.getMetadata() != null && image.getMetadata().getPath() != null) { String fileName = removeFileType(image.getMetadata().getPath()); newName = newName.replace(escapeCharacter + "f", fileName); } else { newName = newName.replace(escapeCharacter + "f", unknownResultCharacter); } } if (newName.length() == 0) { return newName; } // if the user is just typing dont show the last $ // but if he wants a $ at the and (by using $$) allow it and even allow // $$ at the end int escapeCharactersAtEnd = 0; int index = newName.length() - 1; while (index >= 0 && newName.charAt(index--) == escapeCharacter.charAt(0)) { escapeCharactersAtEnd++; } if (escapeCharactersAtEnd % 2 == 1) { newName = newName.substring(0, newName.length() - 1); } if (hasParameter(escapeCharacter.charAt(0))) { newName = newName.replace(random, escapeCharacter); } // set at the end because the original title could contain evil control // sequences if (hasParameter('t')) { newName = newName.replace(escapeCharacter + "t", image.getTitle()); } return newName; }
From source file:org.joda.example.time.DateTimePerformance.java
License:Apache License
private void checkJodaGetYear() { int COUNT = COUNT_VERY_FAST; DateTime dt = new DateTime(GJChronology.getInstance()); for (int i = 0; i < AVERAGE; i++) { start("Joda", "getYear"); for (int j = 0; j < COUNT; j++) { int val = dt.getYear(); if (val == 0) { System.out.println("Anti optimise"); }/* www. j a va2 s . c o m*/ } end(COUNT); } }
From source file:org.joda.example.time.DateTimePerformance.java
License:Apache License
private void checkJISOGetYear() { int COUNT = COUNT_VERY_FAST; DateTime dt = new DateTime(); for (int i = 0; i < AVERAGE; i++) { start("JISO", "getYear"); for (int j = 0; j < COUNT; j++) { int val = dt.getYear(); if (val == 0) { System.out.println("Anti optimise"); }// www .java2s.c o m } end(COUNT); } }
From source file:org.joda.example.time.DateTimePerformance.java
License:Apache License
private void checkJodaSetGetYear() { int COUNT = COUNT_FAST; // Is it fair to use only MutableDateTime here? You decide. // MutableDateTime dt = new MutableDateTime(GJChronology.getInstance()); // for (int i = 0; i < AVERAGE; i++) { // start("Joda", "setGetYear"); // for (int j = 0; j < COUNT; j++) { // dt.setYear(1972); // int val = dt.getYear(); // if (val < 0) {System.out.println("Anti optimise");} // } // end(COUNT); // }/* w w w.jav a 2 s .c o m*/ DateTime dt = new DateTime(GJChronology.getInstance()); for (int i = 0; i < AVERAGE; i++) { start("Joda", "setGetYear"); for (int j = 0; j < COUNT; j++) { dt = dt.year().setCopy(1972); int val = dt.getYear(); if (val < 0) { System.out.println("Anti optimise"); } } end(COUNT); } }
From source file:org.joda.example.time.DateTimePerformance.java
License:Apache License
private void checkJISOSetGetYear() { int COUNT = COUNT_FAST; // Is it fair to use only MutableDateTime here? You decide. // MutableDateTime dt = new MutableDateTime(); // for (int i = 0; i < AVERAGE; i++) { // start("JISO", "setGetYear"); // for (int j = 0; j < COUNT; j++) { // dt.setYear(1972); // int val = dt.getYear(); // if (val < 0) {System.out.println("Anti optimise");} // } // end(COUNT); // }/* www . j a v a 2s. co m*/ DateTime dt = new DateTime(); for (int i = 0; i < AVERAGE; i++) { start("JISO", "setGetYear"); for (int j = 0; j < COUNT; j++) { dt = dt.year().setCopy(1972); int val = dt.getYear(); if (val < 0) { System.out.println("Anti optimise"); } } end(COUNT); } }
From source file:org.joda.example.time.Examples.java
License:Apache License
private void runDateTime() { System.out.println("DateTime"); System.out.println("======="); System.out.println(/*from w ww .j av a 2s. com*/ "DateTime stores a the date and time using millisecs from 1970-01-01T00:00:00Z internally"); System.out.println("DateTime is immutable and thread-safe"); System.out.println(" in = new DateTime()"); DateTime in = new DateTime(); System.out.println("Millisecond time: in.getMillis(): " + in.getMillis()); System.out.println("ISO string version: in.toString(): " + in.toString()); System.out.println("ISO chronology: in.getChronology(): " + in.getChronology()); System.out.println("Your time zone: in.getDateTimeZone(): " + in.getZone()); System.out.println("Change millis: in.withMillis(0): " + in.withMillis(0L)); System.out.println(""); System.out.println("Get year: in.getYear(): " + in.getYear()); System.out.println("Get monthOfYear: in.getMonthOfYear(): " + in.getMonthOfYear()); System.out.println("Get dayOfMonth: in.getDayOfMonth(): " + in.getDayOfMonth()); System.out.println("..."); System.out.println("Property access: in.dayOfWeek().get(): " + in.dayOfWeek().get()); System.out.println( "Day of week as text: in.dayOfWeek().getAsText(): " + in.dayOfWeek().getAsText()); System.out.println( "Day as short text: in.dayOfWeek().getAsShortText(): " + in.dayOfWeek().getAsShortText()); System.out.println("Day in french: in.dayOfWeek().getAsText(Locale.FRENCH):" + in.dayOfWeek().getAsText(Locale.FRENCH)); System.out.println("Max allowed value: in.dayOfWeek().getMaximumValue(): " + in.dayOfWeek().getMaximumValue()); System.out.println("Min allowed value: in.dayOfWeek().getMinimumValue(): " + in.dayOfWeek().getMinimumValue()); System.out.println( "Copy & set to Jan: in.monthOfYear().setCopy(1): " + in.monthOfYear().setCopy(1)); System.out.println( "Copy & add 14 months: in.monthOfYear().addCopy(14): " + in.monthOfYear().addToCopy(14)); System.out.println("Add 14 mnths in field:in.monthOfYear().addWrapFieldCopy(14): " + in.monthOfYear().addWrapFieldToCopy(14)); System.out.println("..."); System.out.println("Convert to Instant: in.toInstant(): " + in.toInstant()); System.out.println("Convert to DateTime: in.toDateTime(): " + in.toDateTime()); System.out.println("Convert to MutableDT: in.toMutableDateTime(): " + in.toMutableDateTime()); System.out.println("Convert to Date: in.toDate(): " + in.toDate()); System.out.println("Convert to Calendar: in.toCalendar(Locale.UK): " + in.toCalendar(Locale.UK).toString().substring(0, 46)); System.out.println("Convert to GregCal: in.toGregorianCalendar(): " + in.toGregorianCalendar().toString().substring(0, 46)); System.out.println(""); System.out.println(" in2 = new DateTime(in.getMillis() + 10)"); DateTime in2 = new DateTime(in.getMillis() + 10); System.out.println("Equals ms and chrono: in.equals(in2): " + in.equals(in2)); System.out.println("Compare millisecond: in.compareTo(in2): " + in.compareTo(in2)); System.out.println("Compare millisecond: in.isEqual(in2): " + in.isEqual(in2)); System.out.println("Compare millisecond: in.isAfter(in2): " + in.isAfter(in2)); System.out.println("Compare millisecond: in.isBefore(in2): " + in.isBefore(in2)); }
From source file:org.jpos.transaction.TxnId.java
License:Open Source License
/** * Creates new TxnId object/* w w w . ja v a 2 s . c o m*/ * * @param dt Transaction's TIMESTAMP DateTime * @param node node id * @param transactionId TransactionManager's ID */ public static TxnId create(DateTime dt, int node, long transactionId) { TxnId id = new TxnId(); if (dt.getZone() != DateTimeZone.UTC) dt = dt.toDateTime(DateTimeZone.UTC); return id.init(dt.getYear() - 2000, dt.getDayOfYear(), dt.getSecondOfDay(), node, transactionId); }
From source file:org.jruby.ext.date.RubyDate.java
License:LGPL
@JRubyMethod // Time.local(year, mon, mday) public RubyTime to_time(ThreadContext context) { final Ruby runtime = context.runtime; DateTime dt = this.dt; dt = new DateTime(adjustJodaYear(dt.getYear()), dt.getMonthOfYear(), dt.getDayOfMonth(), 0, 0, 0, RubyTime.getLocalTimeZone(runtime)); return new RubyTime(runtime, runtime.getTime(), dt); }
From source file:org.jruby.ext.date.RubyDateTime.java
License:LGPL
@JRubyMethod // Time.new(year, mon, mday, hour, min, sec + sec_fraction, (@of * 86400.0)) public RubyTime to_time(ThreadContext context) { final Ruby runtime = context.runtime; DateTime dt = this.dt; dt = new DateTime(adjustJodaYear(dt.getYear()), dt.getMonthOfYear(), dt.getDayOfMonth(), dt.getHourOfDay(), dt.getMinuteOfHour(), dt.getSecondOfMinute(), dt.getMillisOfSecond(), RubyTime.getTimeZone(runtime, this.off)); RubyTime time = new RubyTime(runtime, runtime.getTime(), dt, true); if (subMillisNum != 0) { RubyNumeric usec = (RubyNumeric) subMillis(runtime).op_mul(context, RubyFixnum.newFixnum(runtime, 1_000_000)); time.setNSec(usec.getLongValue()); }//from w w w . j av a 2 s. c o m return time; }