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()));
}
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);
}
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);
}
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());
}
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());
}
Aggregations