List of usage examples for org.joda.time.format DateTimeFormat forPattern
public static DateTimeFormatter forPattern(String pattern)
From source file:com.brandboat.loader.PhoenixDB.java
public static String toTimeStamp(DateTime dt) { DateTimeFormatter dtf = DateTimeFormat.forPattern("yyyy-MM-dd hh:mm:ss"); return dt.toString(dtf); }
From source file:com.bskyb.cg.environments.message.BaseMessageFormat.java
License:Apache License
protected DateTime parseDate(String datestring) throws java.text.ParseException, IndexOutOfBoundsException { DateTimeFormatter df = DateTimeFormat.forPattern(datePattern); DateTime d = new DateTime(); d = df.parseDateTime(datestring);/*from w ww . j a va 2 s. co m*/ return d; }
From source file:com.celtris.exparse.parser.ExcelParser.java
License:Apache License
private FieldParameters processFieldParameters(Field field) { String[] nullString;/* ww w .j a va2s .c om*/ if (field.isAnnotationPresent(NullString.class)) { NullString nullStringAnnotation = field.getAnnotation(NullString.class); nullString = nullStringAnnotation.nulls(); } else { nullString = new String[0]; } boolean lowerCase = false; if (field.isAnnotationPresent(LowerCase.class)) { lowerCase = true; } boolean trim = false; if (field.isAnnotationPresent(Trim.class)) { trim = true; } Parsed parsedAnnotation = field.getAnnotation(Parsed.class); String defaultNullValue = parsedAnnotation.defaultNullRead(); if (defaultNullValue.equals("null")) { defaultNullValue = null; } String dateTimeFormatPatternStr = null; DateTimeFormatter dateTimeFormatter = null; if (field.getType().equals(DateTime.class)) { if (field.isAnnotationPresent(DateTimeFormatPattern.class)) { DateTimeFormatPattern dateTimeFormatPattern = field.getAnnotation(DateTimeFormatPattern.class); dateTimeFormatPatternStr = dateTimeFormatPattern.pattern(); dateTimeFormatter = DateTimeFormat.forPattern(dateTimeFormatPatternStr); } } boolean required = parsedAnnotation.requird(); FieldParameters fieldParameters = new FieldParameters(field, field.getType(), nullString, lowerCase, trim, defaultNullValue, dateTimeFormatPatternStr, dateTimeFormatter, required, properties.get(field.getName())); return fieldParameters; }
From source file:com.chiorichan.plugin.lua.api.OSAPI.java
License:Mozilla Public License
@Override void initialize() { // Push a couple of functions that override original Lua API functions or // that add new functionality to it. lua.getGlobal("os"); // Custom os.clock() implementation returning the time the computer has // been actively running, instead of the native library... lua.pushJavaFunction(new JavaFunction() { @Override//from www . j a v a 2s. c om public int invoke(LuaState lua) { lua.pushNumber(System.currentTimeMillis()); return 1; } }); lua.setField(-2, "clock"); lua.pushJavaFunction(new JavaFunction() { @Override public int invoke(LuaState lua) { String format = lua.getTop() > 0 && lua.isString(1) ? lua.toString(1) : "%d/%m/%y %H:%M:%S"; long time = (long) (lua.getTop() > 1 && lua.isNumber(2) ? lua.toNumber(2) * 1000 / 60 / 60 : System.currentTimeMillis()); DateTime dt = new DateTime(time); if (format == "*t") { lua.newTable(0, 8); lua.pushInteger(dt.year().get()); lua.setField(-2, "year"); lua.pushInteger(dt.monthOfYear().get()); lua.setField(-2, "month"); lua.pushInteger(dt.dayOfMonth().get()); lua.setField(-2, "day"); lua.pushInteger(dt.hourOfDay().get()); lua.setField(-2, "hour"); lua.pushInteger(dt.minuteOfHour().get()); lua.setField(-2, "min"); lua.pushInteger(dt.secondOfMinute().get()); lua.setField(-2, "sec"); lua.pushInteger(dt.dayOfWeek().get()); lua.setField(-2, "wday"); lua.pushInteger(dt.dayOfYear().get()); lua.setField(-2, "yday"); } else lua.pushString(dt.toString(DateTimeFormat.forPattern(format))); return 1; } }); lua.setField(-2, "date"); /* * // Date formatting function. * lua.pushScalaFunction(lua => { * val format = * if (lua.getTop > 0 && lua.isString(1)) lua.toString(1) * else "%d/%m/%y %H:%M:%S" * val time = * if (lua.getTop > 1 && lua.isNumber(2)) lua.toNumber(2) * 1000 / 60 / 60 * else machine.worldTime + 5000 * * val dt = GameTimeFormatter.parse(time) * def fmt(format: String) { * if (format == "*t") { * lua.newTable(0, 8) * lua.pushInteger(dt.year) * lua.setField(-2, "year") * lua.pushInteger(dt.month) * lua.setField(-2, "month") * lua.pushInteger(dt.day) * lua.setField(-2, "day") * lua.pushInteger(dt.hour) * lua.setField(-2, "hour") * lua.pushInteger(dt.minute) * lua.setField(-2, "min") * lua.pushInteger(dt.second) * lua.setField(-2, "sec") * lua.pushInteger(dt.weekDay) * lua.setField(-2, "wday") * lua.pushInteger(dt.yearDay) * lua.setField(-2, "yday") * } * else { * lua.pushString(GameTimeFormatter.format(format, dt)) * } * } * * // Just ignore the allowed leading '!', Minecraft has no time zones... * if (format.startsWith("!")) * fmt(format.substring(1)) * else * fmt(format) * 1 * }) * lua.setField(-2, "date") * * // Return ingame time for os.time(). * lua.pushScalaFunction(lua => { * if (lua.isNoneOrNil(1)) { * // Game time is in ticks, so that each day has 24000 ticks, meaning * // one hour is game time divided by one thousand. Also, Minecraft * // starts days at 6 o'clock, versus the 1 o'clock of timestamps so we * // add those five hours. Thus: * // timestamp = (time + 5000) * 60[kh] * 60[km] / 1000[s] * lua.pushNumber((machine.worldTime + 5000) * 60 * 60 / 1000) * } * else { * def getField(key: String, d: Int) = { * lua.getField(-1, key) * val res = lua.toIntegerX(-1) * lua.pop(1) * if (res == null) * if (d < 0) throw new Exception("field '" + key + "' missing in date table") * else d * else res: Int * } * * lua.checkType(1, LuaType.TABLE) * lua.setTop(1) * * val sec = getField("sec", 0) * val min = getField("min", 0) * val hour = getField("hour", 12) * val mday = getField("day", -1) * val mon = getField("month", -1) * val year = getField("year", -1) * * GameTimeFormatter.mktime(year, mon, mday, hour, min, sec) match { * case Some(time) => lua.pushNumber(time) * case _ => lua.pushNil() * } * } * 1 * }) * lua.setField(-2, "time") */ // Pop the os table. lua.pop(1); }
From source file:com.citrix.g2w.webdriver.pages.BasePage.java
License:Open Source License
/** * Method used to convert date time object to string date format. * * @param pattern (The pattern of the date time parameter) * @param dateTime (Date and time format to format) * @return formattedDate (formatted date in string) */// ww w. ja va 2s . co m public String convertDateTimeObjectToText(final String pattern, final DateTime dateTime) { DateTimeFormatter dateFormat = DateTimeFormat.forPattern(pattern); String formattedDate = dateFormat.withLocale(this.locale).print(dateTime); return formattedDate; }
From source file:com.citrix.g2w.webdriver.pages.BasePage.java
License:Open Source License
/** * Method used to convert string date format to date time object. * * @param pattern// w w w .ja v a 2 s . c om * (The pattern of the date time string parameter) * @param dateTimeString * (Date and time format in String) * @return dateTime (date time object) */ public DateTime convertDateTimeTextToObject(final String pattern, final String dateTimeString) { DateTimeFormatter format = DateTimeFormat.forPattern(pattern); DateTime dateTime = format.withLocale(this.locale).parseDateTime(dateTimeString); return dateTime; }
From source file:com.citrix.g2w.webdriver.pages.BasePage.java
License:Open Source License
/** * Method to set the date value.//from w w w.j a v a 2 s . com * * @param inputId * (id of an element) * @param date * (date object) */ public void setDate(final String inputId, final DateTime date) { DateTimeFormatter fmt = DateTimeFormat .forPattern(this.messages.getMessage("date.format.generateReport.startAndEnd", null, this.locale)); ((JavascriptExecutor) this.driver).executeScript("document.getElementById('" + inputId + "').value = '" + fmt.withLocale(this.locale).print(date) + "'"); }
From source file:com.citrix.g2w.webdriver.pages.BasePage.java
License:Open Source License
/** * Method used to set start and end dates for custom report generation. * //from www . jav a 2 s . c o m * @param startDate * (Start date for custom report) * @param endDate * (End date for custom report) */ public void setDateRangeForReportGeneration(final DateTime startDate, final DateTime endDate) { DateTimeFormatter fmt = DateTimeFormat .forPattern(this.messages.getMessage("date.format.generateReport.startAndEnd", null, this.locale)); if (startDate != null) { ((JavascriptExecutor) this.driver).executeScript("document.getElementById('from-date').value = '" + fmt.withLocale(this.locale).print(startDate) + "'"); } if (endDate != null) { ((JavascriptExecutor) this.driver).executeScript("document.getElementById('to-date').value = '" + fmt.withLocale(this.locale).print(endDate) + "'"); } }
From source file:com.citrix.g2w.webdriver.pages.recordings.RecordingViewData.java
License:Open Source License
public RecordingViewData(String name, String email, String date, String time, String pattern, Locale locale) { date = date.trim();/* ww w . j a v a 2 s. c o m*/ time = time.trim(); pattern = pattern.trim(); this.name = name; this.email = email; // Ignoring time zone data for tests since currently no good way to parse timezone unambiguously this.viewTime = DateTime.parse(date + " " + time.substring(0, time.lastIndexOf(" ")), DateTimeFormat.forPattern(pattern.substring(0, pattern.lastIndexOf(" "))).withLocale(locale)); }
From source file:com.citrix.g2w.webdriver.pages.ScheduleAWebinarPage.java
License:Open Source License
/** * Sets the base starting date/* ww w .j a v a2 s . com*/ * @param baseDate DateTime */ private void setBaseDate(final DateTime baseDate) { DateTimeFormatter fmt = DateTimeFormat .forPattern(this.messages.getMessage("date.format.mask.dayInWeekMonthDayYear", null, this.locale)); ((JavascriptExecutor) this.driver) .executeScript("document.getElementById('webinarTimesForm.dateTimes_0.baseDate').value = '" + fmt.withLocale(this.locale).print(baseDate) + "'"); }