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) 

Source Link

Document

Output the instant using the specified format pattern.

Usage

From source file:com.money.manager.ex.utils.MmxDateTimeUtils.java

License:Open Source License

public String getUserStringFromDateTime(DateTime dateTime) {
    if (dateTime == null)
        return "";

    String userDatePattern = getUserDatePattern();

    return dateTime.toString(userDatePattern);
}

From source file:com.mycompany.alarmdatasimulator.simulation.SimulationCore.java

private void registrarOcourrence(String name, DateTime init, Long duration) {
    String format = "dd-MM-yyyy HH:mm:ss.SSS";
    String initStr = init.toString(format);
    String endStr = init.plusSeconds(duration.intValue()).toString(format);
    String durationStr = duration.toString();
    table.addOcourrence(name, initStr, endStr, durationStr);
}

From source file:com.nestedbird.components.bridges.JodaDateTimeSplitBridge.java

License:Open Source License

@Override
public String objectToString(final Object value) {
    final DateTime dateTime = (DateTime) Optional.ofNullable(value).orElse(new DateTime(0));

    return dateTime.toString(DateTimeFormat.forPattern(DATETIME_FORMAT));
}

From source file:com.netflix.raigad.backup.S3RepositorySettingsParams.java

License:Apache License

public String formatDate(DateTime dateTime, String dateFormat) {
    DateTimeFormatter fmt = DateTimeFormat.forPattern(dateFormat);
    return dateTime.toString(fmt);
}

From source file:com.netflix.raigad.utils.SystemUtils.java

License:Apache License

public static String formatDate(DateTime dateTime, String dateFormat) {
    DateTimeFormatter fmt = DateTimeFormat.forPattern(dateFormat);
    return dateTime.toString(fmt);
}

From source file:com.netsteadfast.greenstep.bsc.action.MeasureDataCalendarQueryAction.java

License:Apache License

private String handlerDate() throws Exception {
    String dateStr = this.getFields().get("date");
    String frequency = this.getFields().get("frequency");
    String dateStatus = this.getFields().get("dateStatus");
    DateTime dateTime = new DateTime(dateStr);
    if ("-1".equals(dateStatus)) { // 
        if (BscMeasureDataFrequency.FREQUENCY_DAY.equals(frequency)
                || BscMeasureDataFrequency.FREQUENCY_WEEK.equals(frequency)) { // 
            dateTime = dateTime.plusMonths(-1);
        } else { // 
            dateTime = dateTime.plusYears(-1);
        }/*  w  w w .j a v  a2  s  .c o  m*/
    }
    if ("1".equals(dateStatus)) { // 
        if (BscMeasureDataFrequency.FREQUENCY_DAY.equals(frequency)
                || BscMeasureDataFrequency.FREQUENCY_WEEK.equals(frequency)) { // 
            dateTime = dateTime.plusMonths(1);
        } else { // 
            dateTime = dateTime.plusYears(1);
        }
    }
    return dateTime.toString("yyyy-MM-dd");
}

From source file:com.niroshpg.android.earthquakemonitor.Utility.java

License:Apache License

/**
 * Helper method to convert the database representation of the date into something to display
 * to users.  As classy and polished a user experience as "20140102" is, we can do better.
 *
 * @param context Context to use for resource localization
 * @param dateStr The db formatted date string, expected to be of the form specified
 *                in Utility.DATE_FORMAT
 * @return a user-friendly representation of the date.
 *///from   w w w .  ja  v  a 2  s  . c  o  m
public static String getFriendlyDayString(Context context, String dateStr) {
    // The day string for earthquake events uses the following logic:
    // For today: "Today, June 8"
    // For tomorrow:  "Tomorrow"
    // For the next 5 days: "Wednesday" (just the day name)
    // For all days after that: "Mon Jun 8"

    Date todayDate = new Date();
    String todayStr = EarthQuakeDataContract.getDbDateString(todayDate);
    DateTime inputDateUTC = DateTimeFormat.forPattern(DATETIME_FORMAT).withZone(DateTimeZone.UTC)
            .parseDateTime(dateStr);

    // currentTimeZone.inDaylightTime()
    DateTime inputDateCurrentTZ = inputDateUTC
            .toDateTime(DateTimeZone.forOffsetMillis(currentTimeZone.getRawOffset()));

    // If the date we're building the String for is today's date, the format
    // is "Today, June 24"
    if (todayStr.equals(dateStr)) {
        String today = context.getString(R.string.today);
        int formatId = R.string.format_full_friendly_date;
        return String.format(context.getString(formatId, today, getFormattedMonthDay(context, dateStr)));
    } else {

        DateTimeFormatter shortenedDateTimeFormat = DateTimeFormat.forPattern("EEE MMM dd HH:mm:ss");
        return inputDateCurrentTZ.toString(shortenedDateTimeFormat);
        //            }
    }
}

From source file:com.njlabs.amrita.aid.gpms.ui.PassApplyActivity.java

License:Open Source License

private void loadDateTimePicker(final DateTime startDate, final View v, final String toModify) {
    MonthAdapter.CalendarDay calendarDay = new MonthAdapter.CalendarDay();
    calendarDay.setDay(startDate.getYear(), startDate.getMonthOfYear() - 1, startDate.getDayOfMonth());

    CalendarDatePickerDialogFragment cdp = new CalendarDatePickerDialogFragment()
            .setOnDateSetListener(new CalendarDatePickerDialogFragment.OnDateSetListener() {
                @Override//  w  w  w.ja va 2s .c  o  m
                public void onDateSet(CalendarDatePickerDialogFragment dialog, final int year,
                        final int monthOfYear, final int dayOfMonth) {

                    RadialTimePickerDialogFragment rtpd = new RadialTimePickerDialogFragment()
                            .setOnTimeSetListener(new RadialTimePickerDialogFragment.OnTimeSetListener() {
                                @Override
                                public void onTimeSet(RadialTimePickerDialogFragment dialog, int hourOfDay,
                                        int minute) {
                                    Ln.d(minute);
                                    boolean error = false;
                                    DateTime selectedDateTime = new DateTime(year, monthOfYear + 1, dayOfMonth,
                                            hourOfDay, minute);
                                    if (toModify.equals("fromDate")) {
                                        fromDate = selectedDateTime;
                                        findViewById(R.id.to_date_btn).setEnabled(true);
                                    } else if (toModify.equals("toDate")) {
                                        toDate = selectedDateTime;
                                        if (toDate.getMillis() <= fromDate.getMillis()) {
                                            error = true;
                                            Snackbar.make(parentView,
                                                    "The end date should be after the from date.",
                                                    Snackbar.LENGTH_LONG).show();
                                        }
                                    }
                                    if (!error) {
                                        ((Button) v).setText(selectedDateTime.toString(Gpms.dateFormat));
                                    }

                                }
                            }).setStartTime(startDate.getHourOfDay(), (startDate.getMinuteOfHour() - 1 == -1 ? 0
                                    : startDate.getMinuteOfHour() - 1))
                            .setThemeDark(false);
                    rtpd.show(getSupportFragmentManager(), "FRAG_TAG_TIME_PICKER");

                }
            }).setFirstDayOfWeek(Calendar.SUNDAY)
            .setPreselectedDate(startDate.getYear(), startDate.getMonthOfYear() - 1, startDate.getDayOfMonth())
            .setDateRange(calendarDay, null).setThemeLight();
    cdp.show(getSupportFragmentManager(), "FRAG_TAG_DATE_PICKER");

}

From source file:com.pacoapp.paco.shared.util.TimeUtil.java

License:Open Source License

public static String formatDateLong(DateTime dateTime) {
    return dateTime.toString(dateLongFormatter);
}

From source file:com.pacoapp.paco.shared.util.TimeUtil.java

License:Open Source License

public static String formatDateTimeShortNoZone(DateTime dateTime) {
    return dateTime.toString(dateTimeNoZoneShortFormatter);
}