Java Code Examples for java.util.Locale#US

The following examples show how to use java.util.Locale#US . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SyslogConnection.java    From GreasySpoon with GNU Affero General Public License v3.0 6 votes vote down vote up
private void initialize() throws SyslogException {
	try {
		this.socket = new DatagramSocket();
	} catch ( SocketException ex ){
		String message = "error creating syslog udp socket: " + ex.getMessage();
		throw new SyslogException( message );
	}
	if ( this.includeDate ) {
		// We need two separate formatters here, since there is
		// no way to get the single digit date (day of month) to
		// pad with a space instead of a zero.
		this.date1Format = new SimpleDateFormat( "MMM  d HH:mm:ss ", Locale.US );
		this.date2Format = new SimpleDateFormat( "MMM dd HH:mm:ss ", Locale.US );
		this.date1Format.setTimeZone ( TimeZone.getDefault() );
		this.date2Format.setTimeZone ( TimeZone.getDefault() );
	}
}
 
Example 2
Source File: HttpClasspathServerHandler.java    From camunda-bpm-workbench with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Sets the Date and Cache headers for the HTTP Response
 *
 * @param response
 *            HTTP response
 * @param fileToCache
 *            file to extract content type
 */
private static void setDateAndCacheHeaders(HttpResponse response) {
    SimpleDateFormat dateFormatter = new SimpleDateFormat(HTTP_DATE_FORMAT, Locale.US);
    dateFormatter.setTimeZone(TimeZone.getTimeZone(HTTP_DATE_GMT_TIMEZONE));

    // Date header
    Calendar time = new GregorianCalendar();
    response.headers().set(DATE, dateFormatter.format(time.getTime()));

    // Add cache headers
    time.add(Calendar.SECOND, HTTP_CACHE_SECONDS);
    response.headers().set(EXPIRES, dateFormatter.format(time.getTime()));
    response.headers().set(CACHE_CONTROL, "private, max-age=" + HTTP_CACHE_SECONDS);
    response.headers().set(
            LAST_MODIFIED, dateFormatter.format(new Date(ManagementFactory.getRuntimeMXBean().getStartTime())));
}
 
Example 3
Source File: DerOutputStream.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Private helper routine for marshalling a DER UTC/Generalized
 * time/date value. If the tag specified is not that for UTC Time
 * then it defaults to Generalized Time.
 * @param d the date to be marshalled
 * @param tag the tag for UTC Time or Generalized Time
 */
private void putTime(Date d, byte tag) throws IOException {

    /*
     * Format the date.
     */

    TimeZone tz = TimeZone.getTimeZone("GMT");
    String pattern = null;

    if (tag == DerValue.tag_UtcTime) {
        pattern = "yyMMddHHmmss'Z'";
    } else {
        tag = DerValue.tag_GeneralizedTime;
        pattern = "yyyyMMddHHmmss'Z'";
    }

    SimpleDateFormat sdf = new SimpleDateFormat(pattern, Locale.US);
    sdf.setTimeZone(tz);
    byte[] time = (sdf.format(d)).getBytes("ISO-8859-1");

    /*
     * Write the formatted date.
     */

    write(tag);
    putLength(time.length);
    write(time);
}
 
Example 4
Source File: Helper.java    From tilesfx with Apache License 2.0 5 votes vote down vote up
public static final DateTimeFormatter getDateFormat(final Locale LOCALE) {
    if (Locale.US == LOCALE) {
        return DateTimeFormatter.ofPattern("MM/dd/YYYY");
    } else if (Locale.CHINA == LOCALE) {
        return DateTimeFormatter.ofPattern("YYYY.MM.dd");
    } else {
        return DateTimeFormatter.ofPattern("dd.MM.getY()YYY");
    }
}
 
Example 5
Source File: TestTextPrinter.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@DataProvider(name="print_DayOfWeekData")
Object[][] providerDayOfWeekData() {
    return new Object[][] {
        // Locale, pattern, expected text, input DayOfWeek
        {Locale.US, "e",  "1",  DayOfWeek.SUNDAY},
        {Locale.US, "ee", "01", DayOfWeek.SUNDAY},
        {Locale.US, "c",  "1",  DayOfWeek.SUNDAY},

        {Locale.UK, "e",  "1",  DayOfWeek.MONDAY},
        {Locale.UK, "ee", "01", DayOfWeek.MONDAY},
        {Locale.UK, "c",  "1",  DayOfWeek.MONDAY},
    };
}
 
Example 6
Source File: TestResultFormatterTest.java    From buck with Apache License 2.0 5 votes vote down vote up
private TestResultFormatter createNoisyFormatter() {
  return new TestResultFormatter(
      new Ansi(false),
      Verbosity.COMMANDS,
      TestResultSummaryVerbosity.of(true, true),
      Locale.US,
      Optional.of(logPath),
      TimeZone.getTimeZone("America/Los_Angeles"));
}
 
Example 7
Source File: RbnfRoundTripTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * Perform an exhaustive round-trip test on the English spellout rules
 */
@Test
public void TestEnglishSpelloutRT() {
    RuleBasedNumberFormat formatter
                    = new RuleBasedNumberFormat(Locale.US,
                    RuleBasedNumberFormat.SPELLOUT);

    doTest(formatter, -12345678, 12345678);
}
 
Example 8
Source File: TestAccessLogValve.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
@Test
public void testBug54044() throws Exception {

    final int cacheSize = 10;

    SimpleDateFormat sdf =
            new SimpleDateFormat("[dd/MMM/yyyy:HH:mm:ss Z]", Locale.US);
    sdf.setTimeZone(TimeZone.getDefault());

    AccessLogValve.DateFormatCache dfc =
            new AccessLogValve.DateFormatCache(
                    cacheSize, Locale.US, null);

    // Create an array to hold the expected values
    String[] expected = new String[cacheSize];

    // Fill the cache & populate the expected values
    for (int secs = 0; secs < (cacheSize); secs++) {
        dfc.getFormat(secs * 1000);
        expected[secs] = generateExpected(sdf, secs);
    }
    Assert.assertArrayEquals(expected, dfc.cLFCache.cache);


    // Cause the cache to roll-around by one and then confirm
    dfc.getFormat(cacheSize * 1000);
    expected[0] = generateExpected(sdf, cacheSize);
    Assert.assertArrayEquals(expected, dfc.cLFCache.cache);

    // Jump 2 ahead and then confirm (skipped value should be null)
    dfc.getFormat((cacheSize + 2)* 1000);
    expected[1] = null;
    expected[2] = generateExpected(sdf, cacheSize + 2);
    Assert.assertArrayEquals(expected, dfc.cLFCache.cache);

    // Back 1 to fill in the gap
    dfc.getFormat((cacheSize + 1)* 1000);
    expected[1] = generateExpected(sdf, cacheSize + 1);
    Assert.assertArrayEquals(expected, dfc.cLFCache.cache);

    // Return to 1 and confirm skipped value is null
    dfc.getFormat(1 * 1000);
    expected[1] = generateExpected(sdf, 1);
    expected[2] = null;
    Assert.assertArrayEquals(expected, dfc.cLFCache.cache);

    // Go back one further
    dfc.getFormat(0);
    expected[0] = generateExpected(sdf, 0);
    Assert.assertArrayEquals(expected, dfc.cLFCache.cache);

    // Jump ahead far enough that the entire cache will need to be cleared
    dfc.getFormat(42 * 1000);
    for (int i = 0; i < cacheSize; i++) {
        expected[i] = null;
    }
    expected[0] = generateExpected(sdf, 42);
    Assert.assertArrayEquals(expected, dfc.cLFCache.cache);
}
 
Example 9
Source File: ReportUtil.java    From nextreports-server with Apache License 2.0 4 votes vote down vote up
public static void addUrlQueryParameters(Settings settings, Entity entity, Map<String, Object> allParameters, Map<String, Object> urlQueryParameters) throws Exception {
   	
   	if ((urlQueryParameters == null) || (urlQueryParameters.size() == 0)) {
   		return;
   	}
   	
	ro.nextreports.engine.Report nextReport;
	if (entity instanceof Chart) {
		Chart chart = (Chart) entity;
		nextReport = NextUtil.getNextReport(settings, chart);
	} else {
		Report report = (Report) entity;
		nextReport = NextUtil.getNextReport(settings, report);
	}
	Map<String, QueryParameter> parameters = ParameterUtil.getUsedParametersMap(nextReport);

	for (String key : urlQueryParameters.keySet()) {
		Object value = urlQueryParameters.get(key);
		QueryParameter parameter = parameters.get(key);
		if (parameter == null) {
			// mispelled inside embeddd code
			continue;
		}
		String className = parameter.getValueClassName();
		Object convertedValue;
					
   		// on Server Locale can be en_US, fr_FR or ro_RO (from internationalization)
		// we must use a hardcoded one and this must be used when we pass Date parameters inside url
   		SimpleDateFormat sdf = new SimpleDateFormat("MM.dd.yyyy hh:mm", Locale.US);      
		
		if (value instanceof String) {
			convertedValue = ParameterUtil.getParameterValueFromString(className, (String) value, sdf);
		} else {
			// multiple values
			String[] values = (String[]) value;
			Object[] convertedValues = new Object[values.length];
			for (int i = 0, size = values.length; i < size; i++) {
				convertedValues[i] = ParameterUtil.getParameterValueFromString(className, values[i], sdf);
			}
			convertedValue = convertedValues;
		}
		allParameters.put(key, convertedValue);
	}

}
 
Example 10
Source File: TestChronoField.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void test_IsoFields_week_based_year() {
    Locale locale = Locale.US;
    String name = IsoFields.WEEK_OF_WEEK_BASED_YEAR.getDisplayName(locale);
    assertEquals(name, "Week");
}
 
Example 11
Source File: GsonEngine.java    From pippo with Apache License 2.0 4 votes vote down vote up
public ISO8601TimeTypeAdapter() {
    timeFormat = new SimpleDateFormat("HH:mm:ssZ", Locale.US);
}
 
Example 12
Source File: RealMatrixFormatTest.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected Locale getLocale() {
    return Locale.US;
}
 
Example 13
Source File: NanoHTTPD.java    From BookReader with Apache License 2.0 4 votes vote down vote up
/**
         * Sends given response to the socket.
         */
        private void send(OutputStream outputStream) {
            String mime = mimeType;
            SimpleDateFormat gmtFrmt = new SimpleDateFormat(
                    "E, d MMM yyyy HH:mm:ss 'GMT'", Locale.US);
            gmtFrmt.setTimeZone(TimeZone.getTimeZone("GMT"));

            try {
                if (status == null) {
                    throw new Error("sendResponse(): Status can't be null.");
                }
                PrintWriter pw = new PrintWriter(outputStream);
                pw.print("HTTP/1.0 " + status.getDescription() + " \r\n");

                if (mime != null) {
                    pw.print("Content-Type: " + mime + "\r\n");
                }

                if (header == null || header.get("Date") == null) {
                    pw.print("Date: " + gmtFrmt.format(new Date()) + "\r\n");
                }

                if (header != null) {
                    for (String key : header.keySet()) {
                        String value = header.get(key);
                        pw.print(key + ": " + value + "\r\n");
                    }
                }

                pw.print("\r\n");
                pw.flush();

                sendInputData(outputStream, data);
//              上传文件
                witBook(pw, outputStream);
                outputStream.flush();
                outputStream.close();
                if (data != null)
                    data.close();
            } catch (IOException ioe) {
                // Couldn't write? No can do.
                ioe.printStackTrace();
            }
        }
 
Example 14
Source File: Tools.java    From isu with GNU General Public License v3.0 4 votes vote down vote up
public static String getDate() {
    DateFormat dateformate = new SimpleDateFormat("MMM_dd_yyyy_HH_mm", Locale.US);
    Date date = new Date();
    String Final_Date = "_" + dateformate.format(date);
    return Final_Date;
}
 
Example 15
Source File: UtilitiesTest.java    From SlidePager with MIT License 4 votes vote down vote up
/**
 * Tests {@link Utilities#getWeeksBetween(Date, Date)}
 */
public void testGetWeeksBetween(){
    //Check same day
    assertEquals(0, Utilities.getWeeksBetween(new Date(), new Date()));

    //Check one week ago
    Calendar cal = Calendar.getInstance();
    Date now = new Date();
    cal.setTime(now);
    SimpleDateFormat df = new SimpleDateFormat(Utilities.DATE_FULL_STRING_FORMAT, Locale.US);
    while(!df.format(cal.getTime()).toLowerCase().equals("sunday")){
        cal.add(Calendar.DAY_OF_WEEK, -1);
    }
    now = cal.getTime();
    //1 days ago, sat
    cal.add(Calendar.DAY_OF_WEEK, -1);
    assertEquals(1, Utilities.getWeeksBetween(new Date(cal.getTimeInMillis()), now));
    //2 days ago, fri
    cal.add(Calendar.DAY_OF_WEEK, -1);
    assertEquals(1, Utilities.getWeeksBetween(new Date(cal.getTimeInMillis()), now));
    //3 days ago, thru
    cal.add(Calendar.DAY_OF_WEEK, -1);
    assertEquals(1, Utilities.getWeeksBetween(new Date(cal.getTimeInMillis()), now));
    //4 days ago, wen
    cal.add(Calendar.DAY_OF_WEEK, -1);
    assertEquals(1, Utilities.getWeeksBetween(new Date(cal.getTimeInMillis()), now));
    //5 days ago, tue
    cal.add(Calendar.DAY_OF_WEEK, -1);
    assertEquals(1, Utilities.getWeeksBetween(new Date(cal.getTimeInMillis()), now));
    //6 days ago, mon
    cal.add(Calendar.DAY_OF_WEEK, -1);
    assertEquals(1, Utilities.getWeeksBetween(new Date(cal.getTimeInMillis()), now));
    //7 days ago, sun
    cal.add(Calendar.DAY_OF_WEEK, -1);
    assertEquals(2, Utilities.getWeeksBetween(new Date(cal.getTimeInMillis()), now));

    //Check one week to
    cal.setTime(now);
    cal.add(Calendar.DAY_OF_WEEK, 7);
    assertEquals(-2, Utilities.getWeeksBetween(new Date(cal.getTimeInMillis()), now));
}
 
Example 16
Source File: a.java    From letv with Apache License 2.0 4 votes vote down vote up
private a(DateFormat dateFormat, DateFormat dateFormat2) {
    this.a = dateFormat;
    this.b = dateFormat2;
    this.c = new SimpleDateFormat(z[3], Locale.US);
    this.c.setTimeZone(TimeZone.getTimeZone(z[2]));
}
 
Example 17
Source File: FixedDateFormatTest.java    From logging-log4j2 with Apache License 2.0 4 votes vote down vote up
@Test
public void testDaylightSavingToWinterTime() throws Exception {
    final Calendar calendar = Calendar.getInstance();
    calendar.setTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z").parse("2017-11-05 00:00:00 UTC"));

    final SimpleDateFormat usCentral = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss,SSS", Locale.US);
    usCentral.setTimeZone(TimeZone.getTimeZone("US/Central"));

    final SimpleDateFormat utc = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss,SSS", Locale.US);
    utc.setTimeZone(TimeZone.getTimeZone("UTC"));

    final FixedDateFormat fixedUsCentral = FixedDateFormat.create(DEFAULT, TimeZone.getTimeZone("US/Central"));
    final FixedDateFormat fixedUtc = FixedDateFormat.create(DEFAULT, TimeZone.getTimeZone("UTC"));

    final String[][] expectedDstAndNoDst = {
            // US/Central, UTC
            { "2017-11-04 19:00:00,000", "2017-11-05 00:00:00,000" }, //
            { "2017-11-04 20:00:00,000", "2017-11-05 01:00:00,000" }, //
            { "2017-11-04 21:00:00,000", "2017-11-05 02:00:00,000" }, //
            { "2017-11-04 22:00:00,000", "2017-11-05 03:00:00,000" }, //
            { "2017-11-04 23:00:00,000", "2017-11-05 04:00:00,000" }, //
            { "2017-11-05 00:00:00,000", "2017-11-05 05:00:00,000" }, //
            { "2017-11-05 01:00:00,000", "2017-11-05 06:00:00,000" }, //  DST jump at 2am US central time
            { "2017-11-05 01:00:00,000", "2017-11-05 07:00:00,000" }, //
            { "2017-11-05 02:00:00,000", "2017-11-05 08:00:00,000" }, //
            { "2017-11-05 03:00:00,000", "2017-11-05 09:00:00,000" }, //
            { "2017-11-05 04:00:00,000", "2017-11-05 10:00:00,000" }, //
            { "2017-11-05 05:00:00,000", "2017-11-05 11:00:00,000" }, //
            { "2017-11-05 06:00:00,000", "2017-11-05 12:00:00,000" }, //
            { "2017-11-05 07:00:00,000", "2017-11-05 13:00:00,000" }, //
            { "2017-11-05 08:00:00,000", "2017-11-05 14:00:00,000" }, //
            { "2017-11-05 09:00:00,000", "2017-11-05 15:00:00,000" }, //
            { "2017-11-05 10:00:00,000", "2017-11-05 16:00:00,000" }, //
            { "2017-11-05 11:00:00,000", "2017-11-05 17:00:00,000" }, //
            { "2017-11-05 12:00:00,000", "2017-11-05 18:00:00,000" }, //
            { "2017-11-05 13:00:00,000", "2017-11-05 19:00:00,000" }, //
            { "2017-11-05 14:00:00,000", "2017-11-05 20:00:00,000" }, //
            { "2017-11-05 15:00:00,000", "2017-11-05 21:00:00,000" }, //
            { "2017-11-05 16:00:00,000", "2017-11-05 22:00:00,000" }, //
            { "2017-11-05 17:00:00,000", "2017-11-05 23:00:00,000" }, // 24
            { "2017-11-05 18:00:00,000", "2017-11-06 00:00:00,000" }, //
            { "2017-11-05 19:00:00,000", "2017-11-06 01:00:00,000" }, //
            { "2017-11-05 20:00:00,000", "2017-11-06 02:00:00,000" }, //
            { "2017-11-05 21:00:00,000", "2017-11-06 03:00:00,000" }, //
            { "2017-11-05 22:00:00,000", "2017-11-06 04:00:00,000" }, //
            { "2017-11-05 23:00:00,000", "2017-11-06 05:00:00,000" }, //
            { "2017-11-06 00:00:00,000", "2017-11-06 06:00:00,000" }, //
            { "2017-11-06 01:00:00,000", "2017-11-06 07:00:00,000" }, //
            { "2017-11-06 02:00:00,000", "2017-11-06 08:00:00,000" }, //
            { "2017-11-06 03:00:00,000", "2017-11-06 09:00:00,000" }, //
            { "2017-11-06 04:00:00,000", "2017-11-06 10:00:00,000" }, //
            { "2017-11-06 05:00:00,000", "2017-11-06 11:00:00,000" }, //
    };

    final TimeZone tz = TimeZone.getTimeZone("US/Central");
    for (int i = 0; i < 36; i++) {
        final Date date = calendar.getTime();
        //System.out.println(usCentral.format(date) + ", Fixed: " + fixedUsCentral.format(date.getTime()) + ", utc: " + utc.format(date));
        assertEquals("SimpleDateFormat TZ=US Central", expectedDstAndNoDst[i][0], usCentral.format(date));
        assertEquals("SimpleDateFormat TZ=UTC", expectedDstAndNoDst[i][1], utc.format(date));
        assertEquals("FixedDateFormat TZ=US Central", expectedDstAndNoDst[i][0], fixedUsCentral.format(date.getTime()));
        assertEquals("FixedDateFormat TZ=UTC", expectedDstAndNoDst[i][1], fixedUtc.format(date.getTime()));
        calendar.add(Calendar.HOUR_OF_DAY, 1);
    }
}
 
Example 18
Source File: PreparedStatement.java    From Komondor with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Set a parameter to a java.sql.Timestamp value. The driver converts this
 * to a SQL TIMESTAMP value when it sends it to the database.
 * 
 * @param parameterIndex
 *            the first parameter is 1, the second is 2, ...
 * @param x
 *            the parameter value
 * @param tz
 *            the timezone to use
 * 
 * @throws SQLException
 *             if a database-access error occurs.
 */
private void setTimestampInternal(int parameterIndex, Timestamp x, Calendar targetCalendar, TimeZone tz, boolean rollForward) throws SQLException {
    if (x == null) {
        setNull(parameterIndex, java.sql.Types.TIMESTAMP);
    } else {
        checkClosed();

        if (!this.sendFractionalSeconds) {
            x = TimeUtil.truncateFractionalSeconds(x);
        }

        if (!this.useLegacyDatetimeCode) {
            newSetTimestampInternal(parameterIndex, x, targetCalendar);
        } else {
            Calendar sessionCalendar = this.connection.getUseJDBCCompliantTimezoneShift() ? this.connection.getUtcCalendar()
                    : getCalendarInstanceForSessionOrNew();

            x = TimeUtil.changeTimezone(this.connection, sessionCalendar, targetCalendar, x, tz, this.connection.getServerTimezoneTZ(), rollForward);

            if (this.connection.getUseSSPSCompatibleTimezoneShift()) {
                doSSPSCompatibleTimezoneShift(parameterIndex, x);
            } else {
                synchronized (this) {
                    if (this.tsdf == null) {
                        this.tsdf = new SimpleDateFormat("''yyyy-MM-dd HH:mm:ss", Locale.US);
                    }

                    StringBuffer buf = new StringBuffer();
                    buf.append(this.tsdf.format(x));

                    if (this.serverSupportsFracSecs) {
                        int nanos = x.getNanos();

                        if (nanos != 0) {
                            buf.append('.');
                            buf.append(TimeUtil.formatNanos(nanos, this.serverSupportsFracSecs, true));
                        }
                    }

                    buf.append('\'');

                    setInternal(parameterIndex, buf.toString()); // SimpleDateFormat is not
                                                                // thread-safe
                }
            }
        }

        this.parameterTypes[parameterIndex - 1 + getParameterIndexOffset()] = Types.TIMESTAMP;
    }
}
 
Example 19
Source File: Vector3DTest.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void testToString() {
    Assert.assertEquals("{3; 2; 1}", new Vector3D(3, 2, 1).toString());
    NumberFormat format = new DecimalFormat("0.000", new DecimalFormatSymbols(Locale.US));
    Assert.assertEquals("{3.000; 2.000; 1.000}", new Vector3D(3, 2, 1).toString(format));
}
 
Example 20
Source File: JSONMap.java    From GreenBits with GNU General Public License v3.0 4 votes vote down vote up
private static SimpleDateFormat getDateFormat() {
    final SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US);
    df.setTimeZone(TimeZone.getTimeZone("UTC"));
    return df;
}