Example usage for org.joda.time.format DateTimeFormatter print

List of usage examples for org.joda.time.format DateTimeFormatter print

Introduction

In this page you can find the example usage for org.joda.time.format DateTimeFormatter print.

Prototype

public String print(ReadablePartial partial) 

Source Link

Document

Prints a ReadablePartial to a new String.

Usage

From source file:com.oneops.search.msg.processor.CIMessageProcessor.java

License:Apache License

private static void convertIllegalDateFormat(Map<String, String> ciAttributes, String name) {
    if (ciAttributes != null && ciAttributes.containsKey(name)) {
        String date = ciAttributes.get(name);

        //Nov  5 21:08:38 2019 GMT
        //Jan 22 18:21:47 2020 GMT
        // Some of the `expires_one` date fields apparently have date format with two spaces, so while this conversion is a hack,
        // until we migrate to newer ES version and change the mapping we need to accommodate both, since single DateTimeFormat can't handle it.
        DateTimeFormatter wrongFormat = DateTimeFormat.forPattern("MMM dd HH:mm:ss yyyy z");
        DateTimeFormatter wrongFormat2 = DateTimeFormat.forPattern("MMM  dd HH:mm:ss yyyy z");

        /// 2020-01-22T18:21:47
        DateTimeFormatter rightFormat = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss");
        try {/*  w w  w.ja v  a2 s  .  c  o  m*/
            ciAttributes.put(name, rightFormat.print(wrongFormat.parseMillis(date)));
        } catch (Exception e) {
            try {
                ciAttributes.put(name, rightFormat.print(wrongFormat2.parseMillis(date)));
            } catch (Exception ignore) {
                // do nothing, unexpected date format
            }
        }
    }
}

From source file:com.pokescanner.MapsActivity.java

License:Open Source License

public String getTimeEstimate(int val) {
    int calculatedValue = hexagonal_number(val) * SettingsController.getSettings(this).getServerRefresh()
            * 1000;/*  w  w  w .ja va2s.  co m*/
    long millis = calculatedValue;
    DateTime dt = new DateTime(millis);
    DateTimeFormatter fmt = DateTimeFormat.forPattern("mm:ss");
    return fmt.print(dt);
}

From source file:com.pokescanner.objects.Pokemons.java

License:Open Source License

public MarkerOptions getMarker(Context context, int scale) {
    String uri = "p" + getNumber();
    int resourceID = context.getResources().getIdentifier(uri, "drawable", context.getPackageName());

    Interval interval;// w w  w  .ja v  a2  s  .c o  m
    //Find our interval
    interval = new Interval(new Instant(), getDate());
    //turn our interval into MM:SS
    DateTime dt = new DateTime(interval.toDurationMillis());
    DateTimeFormatter fmt = DateTimeFormat.forPattern("mm:ss");
    String timeOut = fmt.print(dt);
    //set our location
    LatLng position = new LatLng(getLatitude(), getLongitude());

    Bitmap out = DrawableUtils.writeTextOnDrawable(resourceID, timeOut, scale, context);

    String name = getName();
    name = name.substring(0, 1).toUpperCase() + name.substring(1).toLowerCase();

    MarkerOptions pokeIcon = new MarkerOptions().icon(BitmapDescriptorFactory.fromBitmap(out))
            .position(position).title(name).snippet(timeOut);

    return pokeIcon;
}

From source file:com.popdeem.sdk.uikit.utils.PDUIUtils.java

License:Open Source License

/**
 * Format a Unix Time stamp for the given format
 *
 * @param date   Unix Time stamp in seconds
 * @param format Format to use when converting.
 * @return Formatted date String/*  w  w w  .  ja v a2  s . c o  m*/
 */
public static String convertUnixTimeToDate(long date, String format) {
    DateTime dateTime = new DateTime(date * 1000);
    DateTimeFormatter formatter = DateTimeFormat.forPattern(format);
    return formatter.print(dateTime);
}

From source file:com.precioustech.fxtrading.tradingbot.social.twitter.tweethandler.AbstractFXTweetHandler.java

License:Apache License

private void setStartTimeAsStr() {
    DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd");
    startTimeAsStr = formatter.print(this.startTime);
}

From source file:com.predic8.membrane.core.interceptor.apimanagement.rateLimiter.AMRateLimiter.java

License:Apache License

public void setResponseToServiceUnavailable(Exchange exc, PolicyRateLimit prl)
        throws UnsupportedEncodingException {
    Header hd = new Header();
    DateTimeFormatter dateFormatter = DateTimeFormat.forPattern("EEE, dd MMM yyyy HH:mm:ss 'GMT'").withZoneUTC()
            .withLocale(Locale.US);
    hd.add("Date", dateFormatter.print(DateTime.now()));
    hd.add("X-LimitDuration", PeriodFormat.getDefault().print(prl.getInterval().toPeriod()));
    hd.add("X-LimitRequests", Integer.toString(prl.getRequests()));
    String ip = exc.getRemoteAddrIp();
    DateTime availableAgainDateTime = prl.getNextCleanup();
    hd.add("X-LimitReset", Long.toString(availableAgainDateTime.getMillis()));

    /*StringBuilder bodyString = new StringBuilder();
    DateTimeFormatter dtFormatter = DateTimeFormat.forPattern("HH:mm:ss aa");
    bodyString.append(ip).append(" exceeded the rate limit of ").append(prl.getRequests())
        .append(" requests per ")/*from   w w  w  .  jav  a 2s.c om*/
        .append(PeriodFormat.getDefault().print(prl.getInterval().toPeriod()))
        .append(". The next request can be made at ").append(dtFormatter.print(availableAgainDateTime));*/

    DateTimeFormatter dtFormatter = DateTimeFormat.forPattern("HH:mm:ss aa");
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    JsonGenerator jgen = null;
    try {
        jgen = new JsonFactory().createGenerator(os);
        jgen.writeStartObject();
        jgen.writeObjectField("Statuscode", 429);
        jgen.writeObjectField("Message",
                "The rate limit of " + prl.getRequests() + " requests in "
                        + prl.getInterval().getStandardSeconds()
                        + " seconds is exceeded. The next requests can be made at "
                        + dtFormatter.print(availableAgainDateTime));
        jgen.writeEndObject();
        jgen.close();
    } catch (IOException ignored) {
    }

    Response resp = Response.ResponseBuilder.newInstance().status(429, "Too Many Requests.").header(hd)
            .contentType("application/json").body(os.toByteArray()).build();
    exc.setResponse(resp);
}

From source file:com.predic8.membrane.core.interceptor.ratelimit.RateLimitInterceptor.java

License:Apache License

public void setResponseToServiceUnavailable(Exchange exc) throws UnsupportedEncodingException {

    Header hd = new Header();
    DateTimeFormatter dateFormatter = DateTimeFormat.forPattern("EEE, dd MMM yyyy HH:mm:ss 'GMT'").withZoneUTC()
            .withLocale(Locale.US);
    hd.add("Date", dateFormatter.print(DateTime.now()));
    hd.add("X-LimitDuration",
            PeriodFormat.getDefault().print(rateLimitStrategy.requestLimitDuration.toPeriod()));
    hd.add("X-LimitRequests", Integer.toString(rateLimitStrategy.requestLimit));
    String ip = exc.getRemoteAddrIp();
    DateTime availableAgainDateTime = rateLimitStrategy.getServiceAvailableAgainTime(ip);
    hd.add("X-LimitReset", Long.toString(availableAgainDateTime.getMillis()));

    StringBuilder bodyString = new StringBuilder();
    DateTimeFormatter dtFormatter = DateTimeFormat.forPattern("HH:mm:ss aa");
    bodyString.append(ip).append(" exceeded the rate limit of ").append(rateLimitStrategy.requestLimit)
            .append(" requests per ")
            .append(PeriodFormat.getDefault().print(rateLimitStrategy.requestLimitDuration.toPeriod()))
            .append(". The next request can be made at ").append(dtFormatter.print(availableAgainDateTime));

    Response resp = ResponseBuilder.newInstance().status(429, "Too Many Requests.")
            .contentType(MimeType.TEXT_PLAIN_UTF8).header(hd).body(bodyString.toString()).build();
    exc.setResponse(resp);//from   ww  w . j  a v  a  2s .c om
}

From source file:com.pungwe.db.io.DBObjectWriter.java

License:Apache License

private void writeDate(DateTime date) throws IOException {
    DateTimeFormatter fmt = ISODateTimeFormat.dateTime();
    output.writeUTF(fmt.print(date));
}

From source file:com.qatickets.domain.common.DateHelper.java

License:Open Source License

public static String currentDate(UserProfile user, String pattern) {
    DateTime dt = new DateTime(user.getDateTimeZone());
    DateTimeFormatter dtf = DateTimeFormat.forPattern(pattern);
    return dtf.print(dt);
}

From source file:com.qatickets.domain.common.DateHelper.java

License:Open Source License

public static String format(UserProfile user, Date dateUTC, String pattern) {
    if (dateUTC == null) {
        return null;
    }//ww  w.ja  v  a 2 s  .  c  om
    DateTimeFormatter dtf = DateTimeFormat.forPattern(pattern);
    return dtf.print(toUserTimeZone(user, dateUTC));
}