Java Code Examples for java.util.Locale.US

The following are Jave code examples for showing how to use US of the java.util.Locale class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: lams   File: PreparedStatement.java   View Source Code Vote up 6 votes
/**
 * Set a parameter to a java.sql.Date value. The driver converts this to a
 * SQL DATE 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 cal
 *            the calendar to interpret the date with
 * 
 * @exception SQLException
 *                if a database-access error occurs.
 */
public void setDate(int parameterIndex, java.sql.Date x, Calendar cal) throws SQLException {
    if (x == null) {
        setNull(parameterIndex, java.sql.Types.DATE);
    } else {
        if (!this.useLegacyDatetimeCode) {
            newSetDateInternal(parameterIndex, x, cal);
        } else {
            synchronized (checkClosed().getConnectionMutex()) {
                if (this.ddf == null) {
                    this.ddf = new SimpleDateFormat("''yyyy-MM-dd''", Locale.US);
                }
                if (cal != null) {
                    this.ddf.setTimeZone(cal.getTimeZone());
                }

                setInternal(parameterIndex, this.ddf.format(x));

                this.parameterTypes[parameterIndex - 1 + getParameterIndexOffset()] = Types.DATE;
            }
        }
    }
}
 
Example 2
Project: unitimes   File: RoomAvailabilityService.java   View Source Code Vote up 6 votes
protected Hashtable<Room, HashSet<TimeBlock>> readResponse(Document response) throws ParseException {
    SimpleDateFormat dateFormat = new SimpleDateFormat(response.getRootElement().attributeValue("dateFormat","MM/dd/yyyy"), Locale.US);
    SimpleDateFormat timeFormat = new SimpleDateFormat(response.getRootElement().attributeValue("timeFormat","h:mm a"), Locale.US);
    Hashtable<Room, HashSet<TimeBlock>> availability = new Hashtable<Room, HashSet<TimeBlock>>();
    for (Iterator i=response.getRootElement().elementIterator("room");i.hasNext();) {
        Element roomElement = (Element)i.next();
        Room room = new Room(roomElement);
        HashSet<TimeBlock> roomAvailability = availability.get(room);
        if (roomAvailability==null) {
            roomAvailability = new HashSet<TimeBlock>();
            availability.put(room, roomAvailability);
        }
        for (Iterator j=roomElement.elementIterator("event");j.hasNext();) {
            Element eventElement = (Element)j.next();
            EventTimeBlock event = new EventTimeBlock(eventElement, dateFormat, timeFormat);
            roomAvailability.add(event);
        }
    }
    return availability;
}
 
Example 3
Project: lams   File: PreparedStatement.java   View Source Code Vote up 6 votes
private void newSetDateInternal(int parameterIndex, Date x, Calendar targetCalendar) throws SQLException {
    synchronized (checkClosed().getConnectionMutex()) {
        if (this.ddf == null) {
            this.ddf = new SimpleDateFormat("''yyyy-MM-dd''", Locale.US);
        }

        if (targetCalendar != null) {
            this.ddf.setTimeZone(targetCalendar.getTimeZone());
        } else if (this.connection.getNoTimezoneConversionForDateType()) {
            this.ddf.setTimeZone(this.connection.getDefaultTimeZone());
        } else {
            this.ddf.setTimeZone(this.connection.getServerTimezoneTZ());
        }

        setInternal(parameterIndex, this.ddf.format(x));
    }
}
 
Example 4
Project: intellij-randomness   File: DecimalSettingsDialogTest.java   View Source Code Vote up 5 votes
/**
 * Locale-dependently converts a double into a string.
 *
 * @param decimal a double
 * @return the user's locale's representation of the given double
 */
private static String doubleToString(final double decimal) {
    final Locale locale = Locale.US;
    final NumberFormat formatter = NumberFormat.getInstance(locale);

    return formatter.format(decimal);
}
 
Example 5
Project: BrewBook   File: QueryUtils.java   View Source Code Vote up 5 votes
private static String formatDate(String rawDate) {
        String jsonDatePattern = "yyyy-MM-dd'T'HH:mm:ss'Z'";
        SimpleDateFormat jsonFormatter = new SimpleDateFormat(jsonDatePattern, Locale.US);
        try {
            Date parsedJsonDate = jsonFormatter.parse(rawDate);
            String finalDatePattern = "MMM d, yyy";
            SimpleDateFormat finalDateFormatter = new SimpleDateFormat(finalDatePattern, Locale.US);
            return finalDateFormatter.format(parsedJsonDate);
        } catch (ParseException e) {
            Log.e("QueryUtils", "Error parsing JSON date: ", e);
            return "";
        }
}
 
Example 6
Project: VulcanOTA   File: OTAConfig.java   View Source Code Vote up 5 votes
public SimpleDateFormat getFormat() {
    String format = getProperty(OTAConfig.VERSION_FORMAT, "");
    if (format.isEmpty()) {
        return null;
    }

    try {
        return new SimpleDateFormat(format, Locale.US);
    } catch (IllegalArgumentException | NullPointerException e) {
        OTAUtils.logError(e);
    }
    return null;
}
 
Example 7
Project: IslamicLibraryAndroid   File: UserNote.java   View Source Code Vote up 5 votes
static Comparator<UserNote> getDateCompartor() {
    return (o1, o2) -> {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US);
        try {
            return sdf.parse(o1.timeStampString).compareTo(sdf.parse(o2.timeStampString));
        } catch (ParseException e) {
            e.printStackTrace();
            return 0;
        }
    };
}
 
Example 8
Project: tomcat7   File: RemoteIpFilter.java   View Source Code Vote up 5 votes
@Override
protected SimpleDateFormat[] initialValue() {
    return new SimpleDateFormat[] {
        new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US),
        new SimpleDateFormat("EEEEEE, dd-MMM-yy HH:mm:ss zzz", Locale.US),
        new SimpleDateFormat("EEE MMMM d HH:mm:ss yyyy", Locale.US)
    };
    
}
 
Example 9
Project: the-vigilantes   File: PreparedStatement.java   View Source Code Vote up 5 votes
private void newSetTimeInternal(int parameterIndex, Time x, Calendar targetCalendar) throws SQLException {
    synchronized (checkClosed().getConnectionMutex()) {
        if (this.tdf == null) {
            this.tdf = new SimpleDateFormat("''HH:mm:ss''", Locale.US);
        }

        if (targetCalendar != null) {
            this.tdf.setTimeZone(targetCalendar.getTimeZone());
        } else {
            this.tdf.setTimeZone(this.connection.getServerTimezoneTZ());
        }

        setInternal(parameterIndex, this.tdf.format(x));
    }
}
 
Example 10
Project: openjdk-jdk10   File: DeprDB.java   View Source Code Vote up 5 votes
@Override
public String toString() {
    StringBuilder sb = new StringBuilder();
    Formatter f = new Formatter(sb, Locale.US);
    f.format("=== Types ===%n");
    f.format("%s%n", types.toString());
    f.format("=== Methods ===%n");
    f.format("%s%n", methods.toString());
    f.format("=== Fields ===%n");
    f.format("%s%n", fields.toString());
    return sb.toString();
}
 
Example 11
Project: lams   File: ServerCookie.java   View Source Code Vote up 4 votes
protected DateFormat initialValue() {
    DateFormat df =
        new SimpleDateFormat(OLD_COOKIE_PATTERN, Locale.US);
    df.setTimeZone(TimeZone.getTimeZone("GMT"));
    return df;
}
 
Example 12
Project: BookReader-master   File: NanoHTTPD.java   View Source Code Vote up 4 votes
/**
 * 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();

        if (data != null) {
            int pending = data.available(); // This is to support
            // partial sends, see
            // serveFile()
            int BUFFER_SIZE = 16 * 1024;
            byte[] buff = new byte[BUFFER_SIZE];
            while (pending > 0) {
                int read = data.read(buff, 0,
                        ((pending > BUFFER_SIZE) ? BUFFER_SIZE
                                : pending));
                if (read <= 0) {
                    break;
                }
                outputStream.write(buff, 0, read);
                pending -= read;
            }
        }
        outputStream.flush();
        outputStream.close();
        if (data != null)
            data.close();
    } catch (IOException ioe) {
        // Couldn't write? No can do.
    }
}
 
Example 13
Project: holon-jaxrs   File: FormDataFormats.java   View Source Code Vote up 4 votes
public static DateFormat getTimeFormat() {
	return new SimpleDateFormat(TIME_FORMAT_PATTERN, Locale.US);
}
 
Example 14
Project: FBEventSync   File: Logger.java   View Source Code Vote up 4 votes
protected Logger() {
    mDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS", Locale.US);
}
 
Example 15
Project: EsperantoRadio   File: DRBackendTidsformater.java   View Source Code Vote up 4 votes
public static void main(String[] a) throws Exception {
//    DRBackendTidsformater.servertidsformat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.US); // +01:00 springes over da kolon i +01:00 er ikke-standard Java
    parseUpÄlideigtServertidsformat("2014-02-13T10:03:00+01:00");
    DRBackendTidsformater.servertidsformat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssz", Locale.US); // +01:00 springes over da kolon i +01:00 er ikke-standard Java
    System.out.println("res = "+ parseUpÄlideigtServertidsformat("2017-03-27T04:00:35+0000"));
  }
 
Example 16
Project: tomcat7   File: DateTool.java   View Source Code Vote up 4 votes
@Override
public DateFormat initialValue() {
    DateFormat result = new SimpleDateFormat(asctimePattern, Locale.US);
    result.setTimeZone(GMT_ZONE);
    return result;
}
 
Example 17
Project: letv   File: DefaultDateTypeAdapter.java   View Source Code Vote up 4 votes
DefaultDateTypeAdapter(String datePattern) {
    this(new SimpleDateFormat(datePattern, Locale.US), new SimpleDateFormat(datePattern));
}
 
Example 18
Project: GitHub   File: OkUrlFactoryTest.java   View Source Code Vote up 4 votes
private static String formatDate(Date date) {
  DateFormat rfc1123 = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US);
  rfc1123.setTimeZone(TimeZone.getTimeZone("GMT"));
  return rfc1123.format(date);
}
 
Example 19
Project: oscm   File: PaymentServiceProviderBean.java   View Source Code Vote up 4 votes
/**
 * Sets the payment related information in the XML structure.
 * 
 * @param doc
 *            The root document.
 * @param transaction
 *            The transaction element to be enhanced by the payment element.
 * @param billingResult
 *            The billing result containing the costs.
 * @param paymentType
 *            The payment type to be used.
 */
private void setPaymentXMLParameters(Document doc, Element transaction,
        RequestData data, ChargingData chargingData) {

    Element payment = doc
            .createElement(HeidelpayXMLTags.XML_ELEMENT_PAYMENT);

    String paymentPrefix = getHeidelPayPaymentType(data.getPaymentTypeId());

    payment.setAttribute(HeidelpayXMLTags.XML_ATTRIBUTE_CODE, paymentPrefix
            + ".DB");
    transaction.appendChild(payment);
    Element presentation = doc
            .createElement(HeidelpayXMLTags.XML_ELEMENT_REPRESENTATION);
    Element amount = doc.createElement(HeidelpayXMLTags.XML_ELEMENT_AMOUNT);
    Element currency = doc
            .createElement(HeidelpayXMLTags.XML_ELEMENT_CURRENCY);
    Element usage = doc.createElement(HeidelpayXMLTags.XML_ELEMENT_USAGE);

    // determine costs
    PriceConverter converter = new PriceConverter(Locale.US);
    String costs = converter.getValueToDisplay(
            chargingData.getGrossAmount(), false);
    amount.setTextContent(costs);
    currency.setTextContent(chargingData.getCurrency());

    // Set the text that will appear on user's statement - supplier,
    // period, billing key (128 chars at most)
    String supName = data.getOrganizationName();
    if (supName == null || supName.length() == 0) {
        supName = data.getOrganizationId();
    }
    long billingKey = chargingData.getTransactionId();
    DateFormat df = new SimpleDateFormat(BILL_DATE_FORMAT);
    String periodStart = df.format(chargingData.getPeriodStartTime());
    String periodEnd = df.format(chargingData.getPeriodEndTime());
    usage.setTextContent(String.format("%s, Id: %s, %s - %s", supName,
            String.valueOf(billingKey), periodStart, periodEnd));

    payment.appendChild(presentation);
    presentation.appendChild(amount);
    presentation.appendChild(currency);
    presentation.appendChild(usage);

}
 
Example 20
Project: lib-commons-httpclient   File: DateUtil.java   View Source Code Vote up 3 votes
/**
 * Formats the given date according to the specified pattern.  The pattern
 * must conform to that used by the {@link SimpleDateFormat simple date
 * format} class.
 * 
 * @param date The date to format.
 * @param pattern The pattern to use for formatting the date.  
 * @return A formatted date string.
 * 
 * @throws IllegalArgumentException If the given date pattern is invalid.
 * 
 * @see SimpleDateFormat
 */
public static String formatDate(Date date, String pattern) {
    if (date == null) throw new IllegalArgumentException("date is null");
    if (pattern == null) throw new IllegalArgumentException("pattern is null");
    
    SimpleDateFormat formatter = new SimpleDateFormat(pattern, Locale.US);
    formatter.setTimeZone(GMT);
    return formatter.format(date);
}