public static void addPatternExample() {
    System.out.println("========================================================================");
    System.out.println(" addPatternExample()");
    System.out.println();
    System.out.println(" Use addPattern API to add new '. von' to existing pattern");
    System.out.println("========================================================================");
    // ---addPatternExample
    Date date = new GregorianCalendar(1999, 9, 13, 23, 58, 59).getTime();
    ULocale locale = ULocale.FRANCE;
    // Create an DateTimePatternGenerator instance for the given locale
    DateTimePatternGenerator gen = DateTimePatternGenerator.getInstance(locale);
    SimpleDateFormat format = new SimpleDateFormat(gen.getBestPattern("MMMMddHmm"), locale);
    DateTimePatternGenerator.PatternInfo returnInfo = new DateTimePatternGenerator.PatternInfo();
    // Add '. von' to the existing pattern
    gen.addPattern("dd'. von' MMMM", true, returnInfo);
    // Apply the new pattern
    format.applyPattern(gen.getBestPattern("MMMMddHmm"));
    System.out.println("New Pattern for FRENCH: " + format.toPattern());
    System.out.println("Date Time in new Pattern: " + format.format(date));

    /**
     * output of the sample code:
     * *************************************************************************************************
     * New Pattern for FRENCH: dd. 'von' MMMM HH:mm Date Time in new Pattern: 13. von octobre 23:58
     *
     * <p>***********************************************************************************************
     */
    // ---addPatternExample
  }
 public static String getBackupFileName() {
   SimpleDateFormat format =
       new SimpleDateFormat(ITasksCoreConstants.FILENAME_TIMESTAMP_FORMAT, Locale.ENGLISH);
   String date = format.format(new Date());
   String backupFileName = BACKUP_FILE_PREFIX + date + ".zip"; // $NON-NLS-1$
   return backupFileName;
 }
  private Date getEventDate(String date) {

    SimpleDateFormat format = new SimpleDateFormat("DD.MM.YYYY HH:mm");
    try {
      return format.parse(date);
    } catch (ParseException e) {
      throw new AssertionError("wrong date format");
    }
  }
Exemplo n.º 4
0
 @Override
 public String apply(String dimValue) {
   Date date;
   try {
     date = timeFormatter.parse(dimValue);
   } catch (ParseException e) {
     return dimValue;
   }
   return resultFormatter.format(date);
 }
  public SortedMap<Long, File> getBackupFiles() {

    SortedMap<Long, File> filesMap = new TreeMap<Long, File>();
    String destination = backupFolderPath;

    File backupFolder = new File(destination);
    if (!backupFolder.exists()) {
      return filesMap;
    }

    File[] files = backupFolder.listFiles();
    if (files == null) {
      return filesMap;
    }

    for (File file : files) {
      Matcher matcher = MYLYN_BACKUP_REGEXP.matcher(file.getName());
      if (matcher.find()) {
        Date date = null;
        try {
          SimpleDateFormat format = null;
          String dateText = null;
          Matcher dateFormatMatcher = DATE_FORMAT.matcher(file.getName());
          if (dateFormatMatcher.find()) {
            format =
                new SimpleDateFormat(ITasksCoreConstants.FILENAME_TIMESTAMP_FORMAT, Locale.ENGLISH);
            dateText = dateFormatMatcher.group();
          } else {
            dateFormatMatcher = DATE_FORMAT_OLD.matcher(file.getName());
            if (dateFormatMatcher.find()) {
              format =
                  new SimpleDateFormat(
                      ITasksCoreConstants.OLD_FILENAME_TIMESTAMP_FORMAT, Locale.ENGLISH);
              dateText = dateFormatMatcher.group();
            }
          }
          if (format != null && dateText != null && dateText.length() > 0) {
            date = format.parse(dateText);
          } else {
            continue;
          }
        } catch (IndexOutOfBoundsException e) {
          continue;
        } catch (ParseException e) {
          continue;
        }
        if (date != null && date.getTime() > 0) {
          filesMap.put(new Long(date.getTime()), file);
        }
      }
    }

    return filesMap;
  }
 /**
  * 修改个人信息
  *
  * @param userId 用户ID
  * @param name 名字
  * @param sex 性别
  * @param birthday 生日
  * @param code 工号
  * @param phone 电话号码
  * @param email 电子邮件
  * @param idcard 身份证号
  * @param curUser 当前操作者
  */
 @Transactional(readOnly = false)
 public void personEdit(
     String userId,
     String name,
     int sex,
     String birthday,
     String code,
     String phone,
     String email,
     String idcard,
     String curUser) {
   Date date = new Date();
   User user = (User) dao.queryById(User.class, userId);
   user.setName(name);
   user.setSex(sex);
   try {
     user.setBirthday(sdf.parse(birthday));
   } catch (ParseException e) {
   }
   user.setCode(code);
   user.setPhone(phone);
   user.setEmail(email);
   user.setIdcard(idcard);
   user.setLastEditor(curUser);
   user.setLastUpdateTime(date);
   dao.update(user);
 }
Exemplo n.º 7
0
 private void doHeader(PrintWriter output, String quoteSymbol, String filename) {
   SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
   output.print('\uFEFF');
   output.println(
       quoteSymbol
           + " ***************************************************************************");
   output.println(quoteSymbol + " *");
   output.println(
       quoteSymbol
           + " *  Copyright (C) 2004-"
           + sdf.format(new Date())
           + ", International Business Machines");
   output.println(
       quoteSymbol + " *  Corporation; Unicode, Inc.; and others.  All Rights Reserved.");
   output.println(quoteSymbol + " *");
   output.println(
       quoteSymbol
           + " ***************************************************************************");
   output.println(quoteSymbol + " File: " + filename);
   output.println(quoteSymbol + " Generated from CLDR ");
   output.println(quoteSymbol + "");
 }
 /**
  * 新增用户
  *
  * @param roleId 角色
  * @param areaId 权限区域
  * @param single 个人-范围
  * @param account 帐号
  * @param pwd 密码
  * @param name 名字
  * @param sex 性别
  * @param birthday 生日
  * @param code 工号
  * @param phone 电话号码
  * @param email 电子邮件
  * @param idcard 身份证号
  * @param user 当前操作者
  */
 @Transactional(readOnly = false)
 public void add(
     String roleId,
     String areaId,
     int single,
     String account,
     String pwd,
     String name,
     int sex,
     String birthday,
     String code,
     String phone,
     String email,
     String idcard,
     String curUser) {
   Date date = new Date();
   User user = new User();
   user.setRoleId(roleId);
   user.setAreaId(areaId);
   user.setSingle(single);
   user.setAccount(account);
   user.setPwd(pwd);
   user.setName(name);
   user.setSex(sex);
   try {
     user.setBirthday(sdf.parse(birthday));
   } catch (ParseException e) {
   }
   user.setCode(code);
   user.setPhone(phone);
   user.setEmail(email);
   user.setIdcard(idcard);
   user.setCreator(curUser);
   user.setCreateTime(date);
   user.setLastEditor(curUser);
   user.setLastUpdateTime(date);
   user.setStatus(0);
   dao.create(user);
 }
  public static void replaceFieldTypesExample() {
    // Use repalceFieldTypes API to replace zone 'zzzz' with 'vvvv'
    System.out.println("========================================================================");
    System.out.println(" replaceFieldTypeExample()");
    System.out.println();
    System.out.println(" Use replaceFieldTypes API to replace zone 'zzzz' with 'vvvv");
    System.out.println("========================================================================");
    // ---replaceFieldTypesExample
    Date date = new GregorianCalendar(1999, 9, 13, 23, 58, 59).getTime();
    TimeZone zone = TimeZone.getTimeZone("Europe/Paris");
    ULocale locale = ULocale.FRANCE;
    DateTimePatternGenerator gen = DateTimePatternGenerator.getInstance(locale);
    SimpleDateFormat format = new SimpleDateFormat("EEEE d MMMM y HH:mm:ss zzzz", locale);
    format.setTimeZone(zone);
    String pattern = format.toPattern();
    System.out.println("Pattern before replacement:");
    System.out.println(pattern);
    System.out.println("Date/Time format in fr_FR:");
    System.out.println(format.format(date));
    // Replace zone "zzzz" in the pattern with "vvvv"
    String newPattern = gen.replaceFieldTypes(pattern, "vvvv");
    // Apply the new pattern
    format.applyPattern(newPattern);
    System.out.println("Pattern after replacement:");
    System.out.println(newPattern);
    System.out.println("Date/Time format in fr_FR:");
    System.out.println(format.format(date));

    /**
     * output of the sample code:
     * **************************************************************************************************
     * Pattern before replacement: EEEE d MMMM y HH:mm:ss zzzz Date/Time format in fr_FR: jeudi 14
     * octobre 1999 05:58:59 heure avancée d’Europe centrale Pattern after replacement: EEEE d MMMM
     * y HH:mm:ss vvvv Date/Time format in fr_FR: jeudi 14 octobre 1999 05:58:59 heure de l’Europe
     * centrale
     *
     * <p>************************************************************************************************
     */
    // ---replaceFieldTypesExample
  }
Exemplo n.º 10
0
  /**
   * Iterates through a list of calendar <code>TestCase</code> objects and makes sure that the
   * time-to-fields and fields-to-time calculations work correnctly for the values in each test
   * case.
   */
  public void doTestCases(TestCase[] cases, Calendar cal) {
    cal.setTimeZone(UTC);

    // Get a format to use for printing dates in the calendar system we're testing
    DateFormat format =
        DateFormat.getDateTimeInstance(cal, DateFormat.SHORT, -1, Locale.getDefault());

    final String pattern =
        (cal instanceof ChineseCalendar)
            ? "E MMl/dd/y G HH:mm:ss.S z"
            : "E, MM/dd/yyyy G HH:mm:ss.S z";

    ((SimpleDateFormat) format).applyPattern(pattern);

    // This format is used for printing Gregorian dates.
    DateFormat gregFormat = new SimpleDateFormat(pattern);
    gregFormat.setTimeZone(UTC);

    GregorianCalendar pureGreg = new GregorianCalendar(UTC);
    pureGreg.setGregorianChange(new Date(Long.MIN_VALUE));
    DateFormat pureGregFmt = new SimpleDateFormat("E M/d/yyyy G");
    pureGregFmt.setCalendar(pureGreg);

    // Now iterate through the test cases and see what happens
    for (int i = 0; i < cases.length; i++) {
      logln("\ntest case: " + i);
      TestCase test = cases[i];

      //
      // First we want to make sure that the millis -> fields calculation works
      // test.applyTime will call setTime() on the calendar object, and
      // test.fieldsEqual will retrieve all of the field values and make sure
      // that they're the same as the ones in the testcase
      //
      test.applyTime(cal);
      if (!test.fieldsEqual(cal, this)) {
        errln(
            "Fail: (millis=>fields) "
                + gregFormat.format(test.getTime())
                + " => "
                + format.format(cal.getTime())
                + ", expected "
                + test);
      }

      //
      // If that was OK, check the fields -> millis calculation
      // test.applyFields will set all of the calendar's fields to
      // match those in the test case.
      //
      cal.clear();
      test.applyFields(cal);
      if (!test.equals(cal)) {
        errln(
            "Fail: (fields=>millis) "
                + test
                + " => "
                + pureGregFmt.format(cal.getTime())
                + ", expected "
                + pureGregFmt.format(test.getTime()));
      }
    }
  }
  public static void getBestPatternExample() {
    System.out.println("========================================================================");
    System.out.println(" getBestPatternExample()");
    System.out.println();
    System.out.println(" Use DateTimePatternGenerator to create customized date/time pattern:");
    System.out.println(" yQQQQ,yMMMM, MMMMd, hhmm, jjmm per locale");
    System.out.println("========================================================================");
    // ---getBestPatternExample
    final String[] skeletons = {
      "yQQQQ", // year + full name of quarter, i.e., 4th quarter 1999
      "yMMMM", // year + full name of month, i.e., October 1999
      "MMMMd", // full name of month + day of the month, i.e., October 25
      "hhmm", // 12-hour-cycle format, i.e., 1:32 PM
      "jjmm" // preferred hour format for the given locale, i.e., 24-hour-cycle format for fr_FR
    };
    final ULocale[] locales = {
      new ULocale("en_US"), new ULocale("fr_FR"), new ULocale("zh_CN"),
    };
    DateTimePatternGenerator dtfg = null;
    Date date = new GregorianCalendar(1999, 9, 13, 23, 58, 59).getTime();
    System.out.printf("%-20s%-35s%-35s%-35s\n\n", "Skeleton", "en_US", "fr_FR", "zh_CN");
    for (String skeleton : skeletons) {
      System.out.printf("%-20s", skeleton);
      for (ULocale locale : locales) {
        // create a DateTimePatternGenerator instance for given locale
        dtfg = DateTimePatternGenerator.getInstance(locale);
        // use getBestPattern method to get the best pattern for the given skeleton
        String pattern = dtfg.getBestPattern(skeleton);
        // Constructs a SimpleDateFormat with the best pattern generated above and the given locale
        SimpleDateFormat sdf = new SimpleDateFormat(pattern, locale);
        // Get the format of the given date
        System.out.printf("%-35s", sdf.format(date));
      }
      System.out.println("\n");
    }
    /**
     * output of the sample code:
     * ************************************************************************************************************
     * Skeleton en_US fr_FR zh_CN
     *
     * <p>yQQQQ 4th quarter 1999 4e trimestre 1999 1999年第四季度
     *
     * <p>yMMMM October 1999 octobre 1999 1999年10月
     *
     * <p>MMMMd October 13 13 octobre 10月13日
     *
     * <p>hhmm 11:58 PM 11:58 PM 下午11:58
     *
     * <p>jjmm 11:58 PM 23:58 下午11:58
     *
     * <p>************************************************************************************************************
     */
    // Use DateTime.getPatternInstance to produce the same Date/Time format with predefined constant
    // field value
    final String[] dtfskeleton = {
      DateFormat.YEAR_QUARTER, // year + full name of quarter, i.e., 4th quarter 1999
      DateFormat.YEAR_MONTH, // year + full name of month, i.e., October 1999
      DateFormat.MONTH_DAY // full name of month + day of the month, i.e., October 25
    };
    System.out.printf("%-20s%-35s%-35s%-35s\n\n", "Skeleton", "en_US", "fr_FR", "zh_CN");
    for (String skeleton : dtfskeleton) {
      System.out.printf("%-20s", skeleton);
      for (ULocale locale : locales) {
        // Use DateFormat.getPatternInstance to get the date/time format for the locale,
        // and apply the format to the given date
        String df = DateFormat.getPatternInstance(skeleton, locale).format(date);
        System.out.printf("%-35s", df);
      }
      System.out.println("\n");
    }

    /**
     * output of the sample code:
     * ***********************************************************************************************************
     * Skeleton en_US fr_FR zh_CN
     *
     * <p>yQQQQ 4th quarter 1999 4e trimestre 1999 1999年第四季度
     *
     * <p>yMMMM October 1999 octobre 1999 1999年10月
     *
     * <p>MMMMd October 13 13 octobre 10月13日
     * **********************************************************************************************************
     */
    // ---getBestPatternExample
  }
Exemplo n.º 12
0
 /**
  * Converts the date to a human readable format
  *
  * @param date long
  * @return String date in format yyyyMMdd'T'hhmmss
  */
 public static String readableDate(final long date) {
   String DATE_FORMAT = "yyyyMMdd'T'hhmmss";
   SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
   return sdf.format(date);
 }
Exemplo n.º 13
0
 private String dateToDateFormat(Date date) {
   SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
   String currentDate = dateFormat.format(date);
   return currentDate;
 }