Example usage for org.joda.time DateTime toString

List of usage examples for org.joda.time DateTime toString

Introduction

In this page you can find the example usage for org.joda.time DateTime toString.

Prototype

public String toString(String pattern, Locale locale) throws IllegalArgumentException 

Source Link

Document

Output the instant using the specified format pattern.

Usage

From source file:br.com.fidias.chance4j.Chance.java

License:Open Source License

/**
 * Generate a random birthday.//from   w w  w . j a  v  a  2 s .c  o m
 * <pre>
 * chance.birthdayAsText(AgeOptions.adult, "dd/MM/yyyy hh:mm:ss", new Locale("pt", "BR"));
 * => 06/11/1987 10:27:26
 * </pre>
 *
 * @param options Age options
 * @param pattern Style of the date
 * @param locale Custom locale
 * @return A random birthday
 * @throws ChanceException
 */
public String birthdayAsText(AgeOptions options, String pattern, Locale locale) throws ChanceException {
    DateTime birthday = birthdayDateTime(options);
    return birthday.toString(pattern, locale);
}

From source file:br.com.fidias.chance4j.Chance.java

License:Open Source License

/**
 * Generate a random date as text, between min and max.
 * <pre>//from w  ww .j  av  a  2s  .  c  o  m
 * chance.date(date1, date2, "dd/MM/yyyy", new Locale("pt", "BR"));
 * => 17/07/1977
 * </pre>
 *
 * @param min Minimum value to choose from
 * @param max Maximum value to choose from
 * @param pattern Style of the date
 * @param locale Custom locale
 * @return A random date
 * @throws ChanceException
 */
public String dateAsText(Date min, Date max, String pattern, Locale locale) throws ChanceException {
    DateTime dateTime = dateTime(min.getTime(), max.getTime());
    return dateTime.toString(pattern, locale);
}

From source file:br.com.fidias.chance4j.Chance.java

License:Open Source License

/**
 * Generate a random date, limited to a year.
 * <pre>//from  w  w  w  . ja va2s.  co  m
 * chance.date(1994, "dd/MM/yyyy", new Locale("pt", "BR"));
 * => 19/10/1994
 * </pre>
 *
 * @param year Year of the date
 * @param pattern Style of the date
 * @param locale Custom locale
 * @return A random date
 * @throws ChanceException
 */
public String dateAsText(int year, String pattern, Locale locale) throws ChanceException {
    DateTime dateTime = dateTime(year);
    return dateTime.toString(pattern, locale);
}

From source file:br.com.fidias.chance4j.Chance.java

License:Open Source License

/**
 * Generate a random date with random hour and minute.
 * <pre>//from  ww  w  .ja  v a 2s  .  com
 * chance.timestamp(1994, "dd/MM/yyyy hh:mm:ss", new Locale("pt", "BR"));
 * => 06/11/1994 10:27:26
 * </pre>
 *
 * @param year Year of the timestamp
 * @param pattern Style of the date
 * @param locale Custom locale
 * @return A random date with time
 * @throws ChanceException
 */
public String timestampAsText(int year, String pattern, Locale locale) throws ChanceException {
    DateTime timestamp = dateTimeTimestamp(year);
    return timestamp.toString(pattern, locale);
}

From source file:com.orion.plugin.AdminPlugin.java

License:Open Source License

/**
 * Display the current datetime/*  w  ww  .java2s.c  om*/
 * 
 * @author Daniele Pantaleone
 * @param  command The <tt>Command</tt> object
 * @throws CommandSyntaxException Used to signal a non-recoverable (fatal) syntax exception
 **/
@Usage(message = "Display the current datetime", syntax = "!time")
public void CmdTime(Command command) throws CommandSyntaxException {

    // Checking if we got the correct number of parameters for the command execution
    if (command.getParamNum() != 0)
        throw new CommandSyntaxException("Invalid syntax");

    // Formatting the datetime string
    DateTime datetime = new DateTime(this.orion.timezone);

    // Printing datetime informations in the game chat
    this.console.sayLoudOrPm(command, MessageFormat.format(this.messages.get("time"),
            datetime.toString(this.orion.timeformat, this.orion.locale)));

}

From source file:com.safetys.framework.jmesa.core.filter.DateTimeFilterMatcher.java

License:Apache License

@Override
public boolean evaluate(Object itemValue, String filterValue) {
    if (itemValue == null) {
        return false;
    }/* w w  w.ja  v  a2s  . com*/

    String pattern = getPattern();
    if (pattern == null) {
        logger.debug("The filter (value " + filterValue + ") is trying to match against a date column using "
                + "the DateTimeFilterMatcher, but there is no pattern defined. You need to register a "
                + "DateTimeFilterMatcher to be able to filter against this column.");
        return false;
    }

    Locale locale = null;

    WebContext webContext = getWebContext();
    if (webContext != null) {
        locale = webContext.getLocale();
    }

    DateTime dateTime = (DateTime) itemValue;
    if (locale != null) {
        itemValue = dateTime.toString(pattern, locale);
    } else {
        itemValue = dateTime.toString(pattern);
    }

    String item = String.valueOf(itemValue);
    String filter = String.valueOf(filterValue);
    if (StringUtils.contains(item, filter)) {
        return true;
    }

    return false;
}

From source file:com.safetys.framework.jmesa.view.editor.DateTimeCellEditor.java

License:Apache License

/**
 * Get the formatted date value based on the pattern set.
 *///from   w  w  w.  j  a  va2  s .  c  o  m
@Override
public Object getValue(Object item, String property, int rowcount) {
    Object itemValue = null;

    try {
        itemValue = ItemUtils.getItemValue(item, property);

        if (itemValue == null || StringUtils.isBlank(String.valueOf(itemValue))) {
            return null;
        }

        Locale locale = getWebContext().getLocale();
        DateTime dateTime = (DateTime) itemValue;
        itemValue = dateTime.toString(getPattern(), locale);
    } catch (Exception e) {
        logger.warn("Could not process date time editor with property " + property, e);
    }

    return itemValue;
}

From source file:com.tysanclan.site.projectewok.pages.member.SubscriptionPaymentPage.java

License:Open Source License

public SubscriptionPaymentPage() {
    super("Subscription payments due");

    if (roleService.getTreasurer() == null || roleService.getTreasurer().getPaypalAddress() == null) {
        OverviewPage p = new OverviewPage();
        p.error("No Treasurer, or Treasurer has not setup Paypal");

        throw new RestartResponseAtInterceptPageException(p);
    }//from   w  w w .j a v a 2 s. c o m

    add(new ListView<SubscriptionPayment>("requests", ModelMaker
            .wrap(ImmutableList.copyOf(Iterables.filter(getUser().getPayments(), new UnpaidFilter())))) {
        private static final long serialVersionUID = 1L;

        @Override
        protected void populateItem(ListItem<SubscriptionPayment> item) {
            SubscriptionPayment payment = item.getModelObject();

            DateTime dt = new DateTime(payment.getDate());
            String dateTimeStr = dt.toString("dd MMMM yyyy", Locale.US);

            item.add(new Label("header", "Subscription Payment - " + dateTimeStr));
            item.add(new Label("amount",
                    new DollarSignModel(new Model<BigDecimal>(payment.getSubscription().getAmount()))));

            item.add(new HiddenField<String>("paypalAddress", new Model<String>(
                    roleService.getTreasurer() != null ? roleService.getTreasurer().getPaypalAddress() : null))
                            .add(AttributeModifier.replace("name", "business")));
            item.add(new HiddenField<String>("itemname",
                    new Model<String>("The Tysan Clan - Subscription Payment - " + dateTimeStr)));

            item.add(new HiddenField<String>("itemdesc",
                    new Model<String>("The Tysan Clan - Subscription Payment - " + dateTimeStr))
                            .add(AttributeModifier.replace("name", "item_name"))); //
            item.add(new HiddenField<String>("amount2",
                    new Model<String>(payment.getSubscription().getAmount().toString()))
                            .add(AttributeModifier.replace("name", "amount")));
            item.add(new HiddenField<String>("returnUrl",
                    new Model<String>("https://www.tysanclan.com/processSubscriptionPayment/" + payment.getId()
                            + "/" + paymentDAO.getConfirmationKey(payment) + "/"))
                                    .add(AttributeModifier.replace("name", "return")));
        }
    });
}

From source file:io.symcpe.hendrix.nifi.lmm.interceptor.LMMInterceptor.java

License:Apache License

@Override
public void onTrigger(ProcessContext ctx, ProcessSession session) throws ProcessException {
    FlowFile flowFile = session.get();//  ww w.j a  v a2s  . co  m
    if (flowFile == null) {
        return;
    }

    try {
        AtomicReference<String> message = new AtomicReference<String>();
        session.read(flowFile, true, new InputStreamCallback() {

            @Override
            public void process(InputStream in) throws IOException {
                message.set(IOUtils.toString(in));
            }
        });
        flowFile = session.putAttribute(flowFile, "message", message.get());
        flowFile = session.putAttribute(flowFile, ATTR_TENANT_ID, ctx.getProperty(TENANT_ID).getValue());
        flowFile = session.putAttribute(flowFile, ATTR_API_KEY, ctx.getProperty(API_KEY).getValue());
        flowFile = session.putAttribute(flowFile, ATTR_VERSION, _1);
        String timestamp = ctx.getProperty(TIMESTAMP).evaluateAttributeExpressions(flowFile).getValue();
        DateTime ts = formatter.withZoneUTC().parseDateTime(timestamp);
        flowFile = session.putAttribute(flowFile, ATTR_TIMESTAMP,
                ts.toString(TARGET_TIMESTAMP_PATTERN, Locale.ENGLISH));
        session.transfer(flowFile, SUCCESS);
    } catch (Exception e) {
        flowFile = session.putAttribute(flowFile, "Exception", e.getMessage());
        session.transfer(flowFile, FAILURE);
    }
}