Package com.ibm.icu.text

Examples of com.ibm.icu.text.DateFormat


     * @return a String that results from formatting the given Time using the given TimeZone, Calendar, pattern String and Locale
     */
    public static String formatTime (Time t, TimeZone tz, Calendar cal, String pattern, Locale locale) {
        com.ibm.icu.util.Calendar icuCalendar = cal.toICUCalendar(tz, locale);
       
        DateFormat dateFormat = DateFormat.getDateTimeInstance(icuCalendar, DateFormat.DEFAULT, DateFormat.DEFAULT, locale);
       
        if (pattern != null && pattern.length() != 0 && dateFormat instanceof SimpleDateFormat) {
            ((SimpleDateFormat)dateFormat).applyPattern(pattern);
        }
       
        return dateFormat.format(t.toDate());
    }
View Full Code Here


     * @throws ParseException
     */
    public static Time parseTime(String timeString, TimeZone tz, Calendar cal, String pattern, Locale locale) throws ParseException {
        com.ibm.icu.util.Calendar icuCalendar = cal.toICUCalendar(tz, locale);
       
        DateFormat dateFormat = DateFormat.getDateTimeInstance(icuCalendar, DateFormat.DEFAULT, DateFormat.DEFAULT, locale);
       
        if (pattern != null && pattern.length() != 0 && dateFormat instanceof SimpleDateFormat) {
            ((SimpleDateFormat)dateFormat).applyPattern(pattern);
        }

        Date date = dateFormat.parse(timeString);
        return Time.fromDate(date);
    }
View Full Code Here

     * represented by this ValueNode.
     * @return String
     */
    @Override
    public String getTextValue() {
        DateFormat fmt=DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.LONG);
        fmt.setTimeZone(TimeZone.getDefault());

        return fmt.format(timeValue.toDate());
    }
View Full Code Here

     * @param dateStyle
     * @param timeStyle
     * @return a DateFormat with a pattern drawn from the defaults for the current locale, with the given styles, in UTC
     */
    public static DateFormat getDateFormat(int dateStyle, int timeStyle) {
        DateFormat dateFormat = DateFormat.getDateTimeInstance(dateStyle, timeStyle);
        dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
        return dateFormat;
    }
View Full Code Here

     * @param timeStyle
     * @return a formatted string representing the date value stored in this node
     */
    protected String getTextValue(int dateStyle, int timeStyle) {

        DateFormat dateFormat = getDateFormat(dateStyle, timeStyle);
        return dateFormat.format(getJavaDate());

    }
View Full Code Here

            RelativeDateValueNode dateValueNode = (RelativeDateValueNode) valueEntryPanel.getValueNode();

            // Check.  If it's parseable, then it's valid (of course!).
            // If not parseable, then give a default value of the date in ValueNode.
            DateFormat dateFormat = RelativeTemporalValueNode.getDateFormat(DateFormat.FULL, -1);
           
            try {
                dateFormat.parse(currentText);
            } catch (ParseException pe) {
                currentText = dateFormat.format(dateValueNode.getDateValue());
                changed = true;

            }

        } else if (typeExpr.isNonParametricType(CAL_RelativeTime.TypeConstructors.RelativeTime)) {

            RelativeTimeValueNode timeValueNode = (RelativeTimeValueNode) valueEntryPanel.getValueNode();

            // Check.  If it's parseable, then it's valid (of course!).
            // If not parseable, then give a default value of the time in ValueNode.
            DateFormat timeFormat = RelativeTemporalValueNode.getDateFormat(-1, DateFormat.MEDIUM);
           
            try {
                timeFormat.parse(currentText);
            } catch (ParseException pe) {
                currentText = timeFormat.format(timeValueNode.getTimeValue());
                changed = true;

            }

        } else if (typeExpr.isNonParametricType(CAL_RelativeTime.TypeConstructors.RelativeDateTime)) {

            RelativeDateTimeValueNode dateTimeValueNode = (RelativeDateTimeValueNode) valueEntryPanel.getValueNode();

            // Check.  If it's parseable, then it's valid (of course!).
            // If not parseable, then give a default value of the date time in ValueNode.
            DateFormat dateTimeFormat = RelativeTemporalValueNode.getDateFormat(DateFormat.FULL, DateFormat.MEDIUM);
           
            try {
                dateTimeFormat.parse(currentText);
            } catch (ParseException pe) {
                currentText = dateTimeFormat.format(dateTimeValueNode.getDateTimeValue());
                changed = true;
            }

        } else if (typeExpr.isNonParametricType(CAL_Time.TypeConstructors.Time)) {

            JTimeValueNode valueNode = (JTimeValueNode) valueEntryPanel.getValueNode();

            // Check.  If it's parseable, then it's valid (of course!).
            // If not parseable, then give a default value of the date time in ValueNode.
            DateFormat fmt=DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.LONG);
            fmt.setTimeZone(TimeZone.getDefault());

           
            try {
                fmt.parse(currentText);
            } catch (ParseException pe) {
                currentText = fmt.format(valueNode.getJavaDate());
                changed = true;
            }

        } else if (typeExpr.sameType(typeConstants.getCharListType())) {
View Full Code Here

            newVal = newVal.replace(ListOfCharValueNode.CHAR_RETURN_REPLACE, '\n');
            valueEntryPanel.replaceValueNode(new ListOfCharValueNode(newVal, typeExpr.copyTypeExpr()), true);
       
        } else if (typeExpr.isNonParametricType(CAL_RelativeTime.TypeConstructors.RelativeDate)) {

            DateFormat dateFormat = RelativeTemporalValueNode.getDateFormat(DateFormat.FULL, -1);

            try {
                Date date = dateFormat.parse(newVal);
                valueEntryPanel.replaceValueNode(new RelativeDateValueNode(date, typeExpr.copyTypeExpr()), true);
            } catch (ParseException pe) {
                System.out.println("Error in updateValueNode: Could not parse the Text into a Date value.");
            }

        } else if (typeExpr.isNonParametricType(CAL_RelativeTime.TypeConstructors.RelativeTime)) {

            DateFormat timeFormat = RelativeTemporalValueNode.getDateFormat(-1, DateFormat.MEDIUM);

            try {
                Date date = timeFormat.parse(newVal);
                valueEntryPanel.replaceValueNode(new RelativeTimeValueNode(date, typeExpr.copyTypeExpr()), true);
            } catch (ParseException pe) {
                System.out.println("Error in updateValueNode: Could not parse the Text into a Date value.");
            }

        } else if (typeExpr.isNonParametricType(CAL_RelativeTime.TypeConstructors.RelativeDateTime)) {

            DateFormat dateTimeFormat = RelativeTemporalValueNode.getDateFormat(DateFormat.FULL, DateFormat.MEDIUM);

            try {
                Date date = dateTimeFormat.parse(newVal);
                valueEntryPanel.replaceValueNode(new RelativeDateTimeValueNode(date, typeExpr.copyTypeExpr()), true);
            } catch (ParseException pe) {
                System.out.println("Error in updateValueNode: Could not parse the Text into a Date value.");
            }

        } else if (typeExpr.isNonParametricType(CAL_Time.TypeConstructors.Time)) {
            DateFormat fmt=DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.LONG);
            fmt.setTimeZone(TimeZone.getDefault());

            try {
                Date date = fmt.parse(newVal);
                Time time = Time.fromDate(date);
                valueEntryPanel.replaceValueNode(new JTimeValueNode(time, typeExpr.copyTypeExpr()), true);
            } catch (ParseException pe) {
                System.out.println("Error in updateValueNode: Could not parse the Text into a Date value.");
            }
View Full Code Here

        override = patternData.overrides[dateStyle + 4];
      }
    } else {
      throw new IllegalArgumentException("No date or time style specified");
    }
    DateFormat result = cal.handleGetDateFormat(pattern, override, loc);
    result.setCalendar(cal);
    return result;
  }
View Full Code Here

    fTimeStyle = timeStyle;
    fDateStyle = dateStyle;

    if (fDateStyle != DateFormat.NONE) {
      int newStyle = fDateStyle & ~DateFormat.RELATIVE;
      DateFormat df = DateFormat.getDateInstance(newStyle, locale);
      if (df instanceof SimpleDateFormat) {
        fDateTimeFormat = (SimpleDateFormat) df;
      } else {
        throw new IllegalArgumentException("Can't create SimpleDateFormat for date style");
      }
      fDatePattern = fDateTimeFormat.toPattern();
      if (fTimeStyle != DateFormat.NONE) {
        newStyle = fTimeStyle & ~DateFormat.RELATIVE;
        df = DateFormat.getTimeInstance(newStyle, locale);
        if (df instanceof SimpleDateFormat) {
          fTimePattern = ((SimpleDateFormat) df).toPattern();
        }
      }
    } else {
      // does not matter whether timeStyle is UDAT_NONE, we need something for fDateTimeFormat
      int newStyle = fTimeStyle & ~DateFormat.RELATIVE;
      DateFormat df = DateFormat.getTimeInstance(newStyle, locale);
      if (df instanceof SimpleDateFormat) {
        fDateTimeFormat = (SimpleDateFormat) df;
      } else {
        throw new IllegalArgumentException("Can't create SimpleDateFormat for time style");
      }
View Full Code Here

        if (dateStyle == DF_NONE && timeStyle == DF_NONE
                || dateStyle < 0 || dateStyle >= DF_LIMIT
                || timeStyle < 0 || timeStyle >= DF_LIMIT) {
            throw new IllegalArgumentException("Illegal date format style arguments");
        }
        DateFormat result = null;
        if (dateFormats != null) {
            result = dateFormats[dateStyle][timeStyle];
        }
        if (result != null) {
            result = (DateFormat) result.clone(); // clone for safety
            // Not sure overriding configuration is what we really want...
            result.setTimeZone(getTimeZone());
        } else {
            result = guessDateFormat(dateStyle, timeStyle);
        }
        return result;
    }
View Full Code Here

TOP

Related Classes of com.ibm.icu.text.DateFormat

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.