Example usage for org.joda.time.format DateTimeFormat forPattern

List of usage examples for org.joda.time.format DateTimeFormat forPattern

Introduction

In this page you can find the example usage for org.joda.time.format DateTimeFormat forPattern.

Prototype

public static DateTimeFormatter forPattern(String pattern) 

Source Link

Document

Factory to create a formatter from a pattern string.

Usage

From source file:com.ecofactor.qa.automation.util.DateUtil.java

License:Open Source License

/**
 * Gets the uTC current time stamp.//from  ww w .j  a  v a2  s. c o m
 * @param pattern the pattern
 * @return the uTC current time stamp
 */
public static String getUTCCurrentTimeStamp(String pattern) {

    DateTime startDate = new DateTime(DateTimeZone.UTC);
    DateTimeFormatter fmt = DateTimeFormat.forPattern(pattern);
    return fmt.print(startDate);
}

From source file:com.ecofactor.qa.automation.util.DateUtil.java

License:Open Source License

/**
 * Gets the calendar.//from w w  w. j  a  v a  2 s  .  c  o  m
 * @param startTime the start time
 * @param minutes the minutes
 * @return the calendar
 */
public static Calendar getCalendar(Calendar startTime, int minutes) {

    Calendar endTime = null;
    DateTime start = new DateTime(startTime);
    DateTime end = start.plusMinutes(minutes);
    DateTimeFormatter fmt = DateTimeFormat.forPattern(DATE_FMT_FULL);
    fmt = fmt.withZoneUTC();
    endTime = parseToUTCCalendar(fmt.print(end), DATE_FMT_FULL);
    return endTime;
}

From source file:com.ecofactor.qa.automation.util.DateUtil.java

License:Open Source License

/**
 * Format./*from  w  ww. j  av a2s . c om*/
 * @param calendar the calendar
 * @param pattern the pattern
 * @return the string
 */
public static String formatToUTC(Calendar calendar, String pattern) {

    DateTimeFormatter fmt = DateTimeFormat.forPattern(pattern);
    fmt = fmt.withZoneUTC();
    String strDate = fmt.print(new DateTime(calendar));
    LOGGER.debug("UTC Timestamp " + strDate);
    return strDate;
}

From source file:com.ecofactor.qa.automation.util.DateUtil.java

License:Open Source License

/**
 * Format./*www  .j a va 2  s. c  o m*/
 * @param calendar the calendar
 * @param pattern the pattern
 * @return the string
 */
public static String format(Calendar calendar, String pattern) {

    DateTimeFormatter fmt = DateTimeFormat.forPattern(pattern);
    String strDate = fmt.print(new DateTime(calendar));
    return strDate;
}

From source file:com.ecofactor.qa.automation.util.DateUtil.java

License:Open Source License

/**
 * Format.//from  ww  w  .j  a  v a 2 s. c o m
 * @param date the date
 * @param pattern the pattern
 * @return the string
 */
public static String format(Date date, String pattern) {

    DateTimeFormatter fmt = DateTimeFormat.forPattern(pattern);
    String strDate = fmt.print(new DateTime(date));
    LOGGER.debug("Timestamp " + strDate);
    return strDate;
}

From source file:com.ecofactor.qa.automation.util.DateUtil.java

License:Open Source License

/** 
 * Parses the to zone calendar./*  w  w w. ja v  a 2  s . c  o m*/
 * @param timestamp the timestamp
 * @param pattern the pattern
 * @param timeZone the time zone
 * @return the calendar
 */
public static Calendar parseToZoneCalendar(String timestamp, String pattern, String timeZone) {

    DateTimeFormatter fmt = DateTimeFormat.forPattern(pattern);
    fmt = fmt.withZoneUTC();
    DateTime dt = fmt.parseDateTime(timestamp);
    dt = dt.toDateTime(DateTimeZone.forID(timeZone));
    return dt.toCalendar(Locale.ENGLISH);
}

From source file:com.ecofactor.qa.automation.util.DateUtil.java

License:Open Source License

/**
 * Format.//from  w ww .j  av  a2s . c o m
 * @param timestamp the timestamp
 * @param pattern the pattern
 * @return the string
 */
public static Calendar parseToCalendar(String timestamp, String pattern) {

    DateTimeFormatter fmt = DateTimeFormat.forPattern(pattern);
    DateTime dt = fmt.parseDateTime(timestamp);
    return dt.toCalendar(Locale.ENGLISH);
}

From source file:com.ecofactor.qa.automation.util.DateUtil.java

License:Open Source License

/**
 * Gets the time zone diff./*from   w  ww  . ja v  a2s  . c o  m*/
 * @param timeZone the time zone
 * @return the time zone diff
 */
public static String getTimeZoneDiff(String timeZone) {

    DateTime startDate = new DateTime(DateTimeZone.forID(timeZone));
    DateTimeFormatter fmt = DateTimeFormat.forPattern(DATE_FMT_FULL_TZ);
    String timeval = fmt.print(startDate);
    int lastIndexOfSpace = timeval.lastIndexOf(" ");
    timeval = timeval.substring(lastIndexOfSpace + 1, timeval.length());
    return timeval;
}

From source file:com.edoli.calendarlms.CalendarPagerView.java

License:Apache License

public void setCurrentCalendar(DateTime date) {
    mDate = date;// w  w  w  .  j av a2  s. c  o  m
    mCalendarView.setDate(date);
    mCurrentCalendarView = new CalendarContentView(getContext());
    mCurrentCalendarView.setDate(date);
    mCurrentCalendarView.setCalendarListener(mCalendarListener);

    DateTimeFormatter formatter = DateTimeFormat.forPattern("MMMMMMM yyyy");
    formatter = formatter.withLocale(Locale.ENGLISH);
    String strDate = formatter.print(date);

    mCalendarView.setTitle(strDate);
    mCalendarView.onCalendarChanged(date);

    LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
    addView(mCurrentCalendarView, params);
}

From source file:com.edoli.calendarlms.DayOfWeekAdapter.java

License:Apache License

@SuppressWarnings("deprecation")
@Override/*from   w  ww. j  av a2 s  . co  m*/
public View getView(int position, View convertView, ViewGroup parent) {
    Context context = parent.getContext();
    RelativeLayout view = new RelativeLayout(context);

    AbsListView.LayoutParams layoutParams = new AbsListView.LayoutParams(LayoutParams.MATCH_PARENT, mHeight);
    view.setLayoutParams(layoutParams);

    TextView dayView = new TextView(context);
    RelativeLayout.LayoutParams dayParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT);
    dayParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
    dayParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
    dayView.setLayoutParams(dayParams);

    DateTimeFormatter formatter = DateTimeFormat.forPattern("EEE");
    dayView.setText(formatter.print(mDate.plusDays(position)));
    view.addView(dayView);

    // Set Color
    dayView.setTextColor(mTextColors[position]);
    view.setBackgroundDrawable(mBackground);

    return view;
}