Search in sources :

Example 16 with SimpleDateFormat

use of java.text.SimpleDateFormat in project flink by apache.

the class StaticFileServerHandler method setDateHeader.

/**
	 * Sets the "date" header for the HTTP response.
	 *
	 * @param response HTTP response
	 */
private static void setDateHeader(FullHttpResponse response) {
    SimpleDateFormat dateFormatter = new SimpleDateFormat(HTTP_DATE_FORMAT, Locale.US);
    dateFormatter.setTimeZone(GMT_TIMEZONE);
    Calendar time = new GregorianCalendar();
    response.headers().set(DATE, dateFormatter.format(time.getTime()));
}
Also used : GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) SimpleDateFormat(java.text.SimpleDateFormat)

Example 17 with SimpleDateFormat

use of java.text.SimpleDateFormat in project groovy by apache.

the class InvokeMethodTest method testSetLenientOnDateFormat.

public void testSetLenientOnDateFormat() throws Throwable {
    SimpleDateFormat a = new SimpleDateFormat("MM/dd/yyyy");
    Object value = invoke(a, "setLenient", new Object[] { Boolean.FALSE });
    assertEquals("void method", null, value);
}
Also used : SimpleDateFormat(java.text.SimpleDateFormat)

Example 18 with SimpleDateFormat

use of java.text.SimpleDateFormat in project groovy by apache.

the class DefaultGroovyStaticMethods method parse.

/**
     * Parse a String into a Date instance using the given pattern and TimeZone.
     * This convenience method acts as a wrapper for {@link java.text.SimpleDateFormat}.
     * <p>
     * Note that a new SimpleDateFormat instance is created for every
     * invocation of this method (for thread safety).
     *
     * @param self   placeholder variable used by Groovy categories; ignored for default static methods
     * @param format pattern used to parse the input string.
     * @param input  String to be parsed to create the date instance
     * @param zone   TimeZone to use when parsing
     * @return a new Date instance representing the parsed input string
     * @throws ParseException if there is a parse error
     * @see java.text.SimpleDateFormat#parse(java.lang.String)
     * @since 2.4.1
     */
public static Date parse(Date self, String format, String input, TimeZone zone) throws ParseException {
    SimpleDateFormat sdf = new SimpleDateFormat(format);
    sdf.setTimeZone(zone);
    return sdf.parse(input);
}
Also used : SimpleDateFormat(java.text.SimpleDateFormat)

Example 19 with SimpleDateFormat

use of java.text.SimpleDateFormat in project groovy by apache.

the class DateGroovyMethods method format.

/**
     * <p>Shortcut for {@link java.text.SimpleDateFormat} to output a String representation
     * of this calendar instance.  This method respects the Calendar's assigned
     * {@link java.util.TimeZone}, whereas calling <code>cal.time.format('HH:mm:ss')</code>
     * would use the system timezone.
     * <p>Note that Calendar equivalents of <code>date.getDateString()</code>
     * and variants do not exist because those methods are Locale-dependent.
     * Although a Calendar may be assigned a {@link java.util.Locale}, that information is
     * lost and therefore cannot be used to control the default date/time formats
     * provided by these methods.  Instead, the system Locale would always be
     * used.  The alternative is to simply call
     * {@link java.text.DateFormat#getDateInstance(int, java.util.Locale)} and pass the same Locale
     * that was used for the Calendar.
     *
     * @param self    this calendar
     * @param pattern format pattern
     * @return String representation of this calendar with the given format.
     * @see java.text.DateFormat#setTimeZone(java.util.TimeZone)
     * @see java.text.SimpleDateFormat#format(java.util.Date)
     * @see #format(java.util.Date, String)
     * @since 1.6.0
     */
public static String format(Calendar self, String pattern) {
    SimpleDateFormat sdf = new SimpleDateFormat(pattern);
    sdf.setTimeZone(self.getTimeZone());
    return sdf.format(self.getTime());
}
Also used : SimpleDateFormat(java.text.SimpleDateFormat)

Example 20 with SimpleDateFormat

use of java.text.SimpleDateFormat in project hadoop by apache.

the class TestKeyProvider method testMetadata.

@Test
public void testMetadata() throws Exception {
    //Metadata without description
    DateFormat format = new SimpleDateFormat("y/m/d");
    Date date = format.parse("2013/12/25");
    KeyProvider.Metadata meta = new KeyProvider.Metadata("myCipher", 100, null, null, date, 123);
    assertEquals("myCipher", meta.getCipher());
    assertEquals(100, meta.getBitLength());
    assertNull(meta.getDescription());
    assertEquals(date, meta.getCreated());
    assertEquals(123, meta.getVersions());
    KeyProvider.Metadata second = new KeyProvider.Metadata(meta.serialize());
    assertEquals(meta.getCipher(), second.getCipher());
    assertEquals(meta.getBitLength(), second.getBitLength());
    assertNull(second.getDescription());
    assertTrue(second.getAttributes().isEmpty());
    assertEquals(meta.getCreated(), second.getCreated());
    assertEquals(meta.getVersions(), second.getVersions());
    int newVersion = second.addVersion();
    assertEquals(123, newVersion);
    assertEquals(124, second.getVersions());
    assertEquals(123, meta.getVersions());
    //Metadata with description
    format = new SimpleDateFormat("y/m/d");
    date = format.parse("2013/12/25");
    Map<String, String> attributes = new HashMap<String, String>();
    attributes.put("a", "A");
    meta = new KeyProvider.Metadata("myCipher", 100, "description", attributes, date, 123);
    assertEquals("myCipher", meta.getCipher());
    assertEquals(100, meta.getBitLength());
    assertEquals("description", meta.getDescription());
    assertEquals(attributes, meta.getAttributes());
    assertEquals(date, meta.getCreated());
    assertEquals(123, meta.getVersions());
    second = new KeyProvider.Metadata(meta.serialize());
    assertEquals(meta.getCipher(), second.getCipher());
    assertEquals(meta.getBitLength(), second.getBitLength());
    assertEquals(meta.getDescription(), second.getDescription());
    assertEquals(meta.getAttributes(), second.getAttributes());
    assertEquals(meta.getCreated(), second.getCreated());
    assertEquals(meta.getVersions(), second.getVersions());
    newVersion = second.addVersion();
    assertEquals(123, newVersion);
    assertEquals(124, second.getVersions());
    assertEquals(123, meta.getVersions());
}
Also used : HashMap(java.util.HashMap) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) Test(org.junit.Test)

Aggregations

SimpleDateFormat (java.text.SimpleDateFormat)2847 Date (java.util.Date)1590 ParseException (java.text.ParseException)463 DateFormat (java.text.DateFormat)425 Calendar (java.util.Calendar)307 Test (org.junit.Test)305 ArrayList (java.util.ArrayList)232 File (java.io.File)230 IOException (java.io.IOException)185 GregorianCalendar (java.util.GregorianCalendar)139 HashMap (java.util.HashMap)121 Locale (java.util.Locale)70 DateField (edu.uci.ics.textdb.api.field.DateField)64 DoubleField (edu.uci.ics.textdb.api.field.DoubleField)64 IField (edu.uci.ics.textdb.api.field.IField)64 IntegerField (edu.uci.ics.textdb.api.field.IntegerField)64 StringField (edu.uci.ics.textdb.api.field.StringField)63 TextField (edu.uci.ics.textdb.api.field.TextField)63 Map (java.util.Map)63 Tuple (edu.uci.ics.textdb.api.tuple.Tuple)61