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:org.apache.phoenix.pherf.rules.RulesApplier.java

License:Apache License

public String generateRandomDate(String min, String max) throws Exception {
    DateTimeFormatter fmtr = DateTimeFormat.forPattern(PherfConstants.DEFAULT_DATE_PATTERN)
            .withZone(DateTimeZone.UTC);
    DateTime minDt;/*ww w  .j  ava 2  s .  c o  m*/
    DateTime maxDt;
    DateTime dt;

    minDt = fmtr.parseDateTime(checkDatePattern(min));
    maxDt = fmtr.parseDateTime(checkDatePattern(max));

    // Get Ms Date between min and max
    synchronized (randomDataGenerator) {
        //Make sure date generated is exactly between the passed limits
        long rndLong = randomDataGenerator.nextLong(minDt.getMillis() + 1, maxDt.getMillis() - 1);
        dt = new DateTime(rndLong, PherfConstants.DEFAULT_TIME_ZONE);
    }

    return fmtr.print(dt);
}

From source file:org.apache.phoenix.pherf.rules.RulesApplier.java

License:Apache License

public String getCurrentDate() {
    DateTimeFormatter fmtr = DateTimeFormat.forPattern(PherfConstants.DEFAULT_DATE_PATTERN)
            .withZone(DateTimeZone.UTC);
    ;/*from   w  w  w .j  a va 2  s  .  c o  m*/
    DateTime dt = new DateTime(PherfConstants.DEFAULT_TIME_ZONE);
    return fmtr.print(dt);
}

From source file:org.apache.phoenix.pherf.rules.RulesApplier.java

License:Apache License

public String checkDatePattern(String date) {
    DateTimeFormatter fmtr = DateTimeFormat.forPattern(PherfConstants.DEFAULT_DATE_PATTERN)
            .withZone(DateTimeZone.UTC);
    ;//from ww w .  j  ava 2  s. c  om
    DateTime parsedDate = fmtr.parseDateTime(date);
    return fmtr.print(parsedDate);
}

From source file:org.apache.rave.portal.util.ModelUtil.java

License:Apache License

public static String dateToString(Date date) {
    DateTimeFormatter fmt = ISODateTimeFormat.dateTimeNoMillis();
    DateTime dateTime = new DateTime(date);
    return fmt.print(dateTime);
}

From source file:org.apache.streams.juneau.JodaDateSwap.java

License:Apache License

@Override /* PojoSwap */
public String swap(BeanSession session, DateTime o) {
    DateTimeFormatter dateFormatter = this.dateFormatter;
    if (StringUtils.isNotBlank(
            session.getProperty("format", String.class, RFC3339Utils.UTC_STANDARD_FMT.toString()))) {
        dateFormatter = DateTimeFormat.forPattern(
                session.getProperty("format", String.class, RFC3339Utils.UTC_STANDARD_FMT.toString()));
    }/*from   w  ww  . ja v  a2s . c o m*/
    return dateFormatter.print(o);
}

From source file:org.apache.streams.rss.serializer.SyndEntrySerializer.java

License:Apache License

private void serializeDate(ObjectNode root, Date date, String key) {
    DateTimeFormatter formatter = ISODateTimeFormat.dateTime();
    if (date == null)
        return;// w  w w. j a  va2s  .  com
    root.put(key, formatter.print(date.getTime()));
}

From source file:org.apache.wicket.datetime.DateConverter.java

License:Apache License

/**
 * @see org.apache.wicket.util.convert.IConverter#convertToString(java.lang.Object,
 *      java.util.Locale)/* w  w  w  . j  a  v a2 s. c  o m*/
 */
public String convertToString(Date value, Locale locale) {
    DateTime dt = new DateTime((value).getTime(), getTimeZone());
    DateTimeFormatter format = getFormat(locale);

    if (applyTimeZoneDifference) {
        TimeZone zone = getClientTimeZone();
        if (zone != null) {
            // apply time zone to formatter
            format = format.withZone(DateTimeZone.forTimeZone(zone));
        }
    }
    return format.print(dt);
}

From source file:org.apache.zeppelin.socket.NotebookServer.java

License:Apache License

private void moveFolderToTrash(NotebookSocket conn, HashSet<String> userAndRoles, Notebook notebook,
        Message fromMessage) throws SchedulerException, IOException {
    String folderId = (String) fromMessage.get("id");
    if (folderId == null) {
        return;/*w  w w.jav  a2s.  c om*/
    }

    Folder folder = notebook.getFolder(folderId);
    if (folder != null && !folder.isTrash()) {
        String trashFolderId = Folder.TRASH_FOLDER_ID + "/" + folderId;
        if (notebook.hasFolder(trashFolderId)) {
            DateTime currentDate = new DateTime();
            DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");
            trashFolderId += Folder.TRASH_FOLDER_CONFLICT_INFIX + formatter.print(currentDate);
        }

        fromMessage.put("name", trashFolderId);
        renameFolder(conn, userAndRoles, notebook, fromMessage, "move");
    }
}

From source file:org.artifactory.ui.rest.common.SecurityModelPopulator.java

@Nonnull
public static BaseUser getUserConfiguration(@Nonnull UserInfo user, DateTimeFormatter dateFormatter) {
    BaseUser userConfiguration = new BaseUser();
    userConfiguration.setInternalPasswordDisabled(!user.isAdmin() && user.hasInvalidPassword());
    long lastLoginTimeMillis = user.getLastLoginTimeMillis();
    if (lastLoginTimeMillis > 0) {
        userConfiguration.setLastLoggedIn(dateFormatter.print(lastLoginTimeMillis));
    }//from w w w .  j  a v a2s  .co m
    userConfiguration.setRealm(user.getRealm());
    userConfiguration.setAdmin(user.isAdmin());
    userConfiguration.setEmail(user.getEmail());
    userConfiguration.setName(user.getUsername());
    userConfiguration.setProfileUpdatable(user.isUpdatableProfile());
    if (!("internal".equals(user.getRealm()) || "system".equals(user.getRealm()) || user.getRealm() == null
            || user.getRealm().isEmpty() || user.isAnonymous())) {
        userConfiguration.setExternalRealmLink("Check external status");
    }
    Set<UserGroupInfo> groups = user.getGroups();
    if ((groups != null) && !groups.isEmpty()) {
        userConfiguration
                .setGroups(Sets.newHashSet(Iterables.transform(groups, new Function<UserGroupInfo, String>() {
                    @Override
                    public String apply(@Nullable UserGroupInfo input) {
                        if (input == null) {
                            return null;
                        }
                        return input.getGroupName();
                    }
                })));
    }
    return userConfiguration;
}

From source file:org.basepom.mojo.propertyhelper.DateField.java

License:Apache License

@Override
public Optional<String> getPropertyValue() {
    final DateTimeZone timeZone = dateDefinition.getTimezone().isPresent()
            ? DateTimeZone.forID(dateDefinition.getTimezone().get())
            : DateTimeZone.getDefault();

    final Optional<String> format = dateDefinition.getFormat();
    final DateTimeFormatter formatter;
    if (format.isPresent()) {
        formatter = DateTimeFormat.forPattern(format.get());
    } else {/* w  ww .j av  a  2s .c  o  m*/
        formatter = null;
    }

    DateTime date = getDateTime(valueProvider.getValue(), formatter, timeZone);

    if (date == null && dateDefinition.getValue().isPresent()) {
        date = new DateTime(dateDefinition.getValue().get(), timeZone);
    }

    if (date == null) {
        date = new DateTime(timeZone);
    }

    String result;
    if (formatter != null) {
        result = formatter.print(date);
        valueProvider.setValue(result);
    } else {
        result = date.toString();
        valueProvider.setValue(Long.toString(date.getMillis()));
    }

    if (dateDefinition.getTransformers().isPresent()) {
        result = TransformerRegistry.applyTransformers(dateDefinition.getTransformers().get(), result);
    }
    return Optional.fromNullable(result);
}