Ejemplo n.º 1
0
    /** The key method of <code>Cell</code>: initializes the date cell. */
    private void initCell() {
      switch (layout) {
        case HORIZONTAL:
          day = col + 1;
          break;
        case VERTICAL:
          day = row + 1;
          break;
        case TABLE:
        default:
          setPreferredSize(new Dimension(60, 48));
          if (row == 1 && col < weekCount - firstWeekRest
              || row == getRowCount() - 1 && col >= lastWeekRest) {
            // No days in these cells.
            day = 0;
            setBackground(null);
            setForeground(null);
          } else {
            day = (row - 1) * weekCount + (col - (weekCount - firstWeekRest) + 1);
          }
      }
      if (day == 0) {
        return;
      }
      calendar.set(Calendar.DATE, day);
      try {
        if (isToday(calendar)) {
          setBackground(colors.bgToday);
          setForeground(colors.fgToday);
          setBorder(BorderFactory.createLineBorder(colors.borderToday));
        } else {
          Date d = calendar.getTime();
          try {
            d = getFormattedDate(d);
          } catch (ParseException e) {
            e.printStackTrace();
          }

          switch (calendar.get(Calendar.DAY_OF_WEEK)) {
            case Calendar.SATURDAY:
              setBackground(colors.bgSaturday);
              setForeground(colors.fgSaturday);
              break;
            case Calendar.SUNDAY:
              setBackground(colors.bgSunday);
              setForeground(colors.fgSunday);
              break;
            default:
              setBackground(colors.bgCell);
              setForeground(colors.fgCell);
          }

          setBorder(BorderFactory.createRaisedBevelBorder());
          setOpaque(true); // To display background color
        }
      } catch (ParseException e) {
        e.printStackTrace();
      }
      calendar.set(Calendar.DATE, todayInMonth); // Resume date
    }
Ejemplo n.º 2
0
  public Date transformarJulianaAGregoriadeLong(Long valor) {
    String j = valor.toString();
    Date date = new Date();
    String primerValor = "";
    if (j.length() == 5) {
      try {
        date = new SimpleDateFormat("yyD").parse(j);
      } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    } else {
      primerValor = j.substring(0, 1);
      if (primerValor.equals("1")) {
        String anno = j.substring(1, 3);
        date.setYear(Integer.valueOf("20" + anno) - 1900);
        String s = j.substring(3);
        Date fecha = new Date();
        try {
          fecha = new SimpleDateFormat("D").parse(s);
        } catch (ParseException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
        fecha.setYear(date.getYear());
        return fecha;
      }
    }

    return date;
  }
  public void getPersonalData(Employee employee) {
    if (empName.getText().matches("([a-zA-Z]+ +)*[a-zA-Z]+")) {
      System.out.println("name");

      if (textField_Contact.getText().matches("\\d{10}")) {
        System.out.println("contact");
        if (textField_Email
            .getText()
            .matches(
                "^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$")) {
          System.out.println("mail");
          if (textField_ZipCode.getText().matches("\\d{6}")) {
            System.out.println("zipcode");
            if (getRdbtnFemale().isSelected()) {
              String genderF = getRdbtnFemale().getText();
              System.out.println(genderF);
            }
            if (getRdbtnMale().isSelected()) {
              String male = getRdbtnMale().getText();
              System.out.println(male);
            }
            Address address =
                new Address(
                    textField_StreetName.getText(),
                    (Long.parseLong(textField_ZipCode.getText())),
                    textField_BuildingName.getText(),
                    (String) comboBox_City.getSelectedItem(),
                    (String) comboBox_Country.getSelectedItem());

            System.out.println(address);

            employee = new Employee();
            employee.setName(empName.getText());
            System.out.println(empName.getText());
            employee.setAdress(address);
            AgeCalculator ageCalculator = new AgeCalculator();
            try {
              employee.setBirthDate(concatDate());
              System.out.println("Birthdate" + concatDate());

            } catch (ParseException e2) {
              // TODO Auto-generated catch block
              e2.printStackTrace();
            }
            try {
              employee.setAge(ageCalculator.calculateAge(concatDate()));
            } catch (ParseException e4) {
              // TODO Auto-generated catch block
              e4.printStackTrace();
            }
            employee.getAge();
            employee.setEmail(textField_Email.getText());
            employee.setContactNo(textField_Contact.getText());

            System.out.println(employee);
          }
        }
      }
    }
  }
Ejemplo n.º 4
0
 private void importActivity(JSONObject activity, String portal_image_url) {
   // System.out.println(activity.toString());
   try {
     JSONObject member = activity.getJSONObject("member");
     if (member.containsKey("id")) {
       String title =
           activity.getString("body").replace(activity.getString("image_large_url"), "").trim();
       DBObject photo = new BasicDBObject();
       photo.put("portal_image_url", portal_image_url);
       if (mPhotoCollection.count(photo) > 0) {
         System.err.println(portal_image_url + " already exists");
         return;
       } else {
         System.out.println("Inserting " + portal_image_url);
       }
       String imageSourceUrl =
           Config.PORTAL_URL.startsWith("http:")
               ? portal_image_url.replace("https://", "http://")
               : portal_image_url;
       BufferedImage[] images = ImageUtil.convertImage(new URL(imageSourceUrl));
       if (images == null) {
         System.err.println(portal_image_url + " corrupted");
         return;
       }
       saveThumbnailImages(photo, images, "/" + getFileId(portal_image_url) + ".png");
       photo.put("uploader_user_id", member.getString("id"));
       photo.put("title", title);
       Object exifObj = getExifData(portal_image_url);
       Date date = null;
       if (exifObj instanceof JSONObject) {
         JSONObject exif = (JSONObject) exifObj;
         if (exif.containsKey("date")) {
           try {
             date = FORMAT_DATE_ISO.parse(exif.getString("date"));
           } catch (ParseException e) {
             e.printStackTrace();
           }
         }
         if (exif.containsKey("location")) {
           photo.put("exif_location", exif.getJSONArray("location"));
         }
       }
       if (date == null && activity.containsKey("created_at")) {
         try {
           date = FORMAT_DATE.parse(activity.getString("created_at"));
         } catch (ParseException e) {
           e.printStackTrace();
         }
       }
       if (date != null) {
         photo.put("exif_date", date);
       }
       mPhotoCollection.insert(photo);
       // System.out.println(photo);
       // System.out.println();
     }
   } catch (JSONException | MalformedURLException e) {
     e.printStackTrace();
   }
 }
Ejemplo n.º 5
0
 @Override
 public IQuote read() throws Exception {
   LiveQuote quote = new LiveQuote();
   // Iterate thru the set and create the bean.
   Iterator<String> iterator = template.getFields().iterator();
   while (iterator.hasNext()) {
     String field = iterator.next();
     String pattern = template.getPattern(field);
     Matcher matcher = Pattern.compile(pattern, Pattern.MULTILINE).matcher(source);
     int index = 0;
     if (matcher.find(index)) {
       String match = matcher.group(1);
       match = match.equals("NA") ? "0" : match;
       match = match.replace(",", "");
       match = match.replace(",", "");
       if (field.equals("date")) {
         try {
           quote.setDate(new SimpleDateFormat(template.getDateFormat()).parse(match));
         } catch (ParseException e) {
           // TODO Auto-generated catch block
           e.printStackTrace();
         }
       } else if (field.equals("open")) {
         quote.setOpen(Double.parseDouble(match));
         quote.setClose(0.0);
       } else if (field.equals("high")) {
         quote.setHigh(Double.parseDouble(match));
       } else if (field.equals("low")) {
         quote.setLow(Double.parseDouble(match));
       } else if (field.equals("volume")) {
         quote.setVolume(Integer.parseInt(match));
       } else if (field.equals("lastTradedPrice")) {
         quote.setLastTradedPrice(Double.parseDouble(match));
         quote.setOpen(Double.parseDouble(match));
       } else if (field.equals("lastTradedTime")) {
         try {
           quote.setLastTradedTime(new SimpleDateFormat("HH:mm:ss").parse(match));
           quote.setDate(new SimpleDateFormat("HH:mm:ss").parse(match));
         } catch (ParseException e) {
           // TODO Auto-generated catch block
           e.printStackTrace();
         }
       } else if (field.equals("ask")) {
         quote.setAsk(Double.parseDouble(match));
       } else if (field.equals("askSize")) {
         quote.setAskSize(Integer.parseInt(match));
       } else if (field.equals("bid")) {
         quote.setBid(Double.parseDouble(match));
       } else if (field.equals("bidSize")) {
         quote.setBidSize(Integer.parseInt(match));
       }
     }
   }
   if (prevQuote == null || (prevQuote != null && !prevQuote.equals(quote))) {
     prevQuote = quote;
     return quote;
   } else return null;
 }
Ejemplo n.º 6
0
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    // The action bar home/up action should open or close the drawer.
    // ActionBarDrawerToggle will take care of this.
    if (mDrawerToggle.onOptionsItemSelected(item)) {
      return true;
    }

    if (item.getItemId() == R.id.settings) {
      startActivity(new Intent(this, Prefs.class));
      return true;
    }

    if (item.getTitle().toString().contains("Sort by")) {
      if (sortDir.equals("DESC")) {
        sortDir = "ASC";
      } else {
        sortDir = "DESC";
      }
    }

    if (item.getTitle().toString().equals("Sort by Title")) {
      sortStr = "title";
      try {
        populateMyMovies(lv);
      } catch (ParseException e) {
        e.printStackTrace();
      }
      return true;
    }

    if (item.getTitle().toString().equals("Sort by Rating")) {
      sortStr = "rating";
      try {
        populateMyMovies(lv);
      } catch (ParseException e) {
        e.printStackTrace();
      }
      return true;
    }

    if (item.getTitle().toString().equals("Sort by Theater")) {
      sortStr = "theater_id";
      try {
        populateMyMovies(lv);
      } catch (ParseException e) {
        e.printStackTrace();
      }
      return true;
    }

    switch (item.getItemId()) {
      case android.R.id.home:
        return true;
    }
    return super.onOptionsItemSelected(item);
  }
  public static boolean isFanOn() {
    ArrayList<Date> ON = new ArrayList<Date>();
    ArrayList<Date> OFF = new ArrayList<Date>();

    SimpleDateFormat formater = new SimpleDateFormat("HH:mm");
    String[] s = formater.format(Status.Interval).split(":");
    int Hour_I = Integer.parseInt(s[0]);
    int Min_I = Integer.parseInt(s[1]);

    s = formater.format(Status.Working_Time).split(":");
    int Hour_W = Integer.parseInt(s[0]);
    int Min_W = Integer.parseInt(s[1]);

    if (Hour_W == 0 && Min_W == 0) {
      return false;
    }
    if (Hour_I == 0 && Min_I == 0) {
      return true;
    }

    int current = 0;
    while (current < 1440) {
      try {
        Date on = formater.parse(current / 60 + ":" + current % 60);
        ON.add(on);
      } catch (ParseException e) {
        e.printStackTrace();
      }

      try {
        Date off =
            formater.parse((((current + Min_W) / 60) + Hour_W) + ":" + (current + Min_W) % 60);
        if (current + Hour_W * 60 + Min_W >= 1440) {
          OFF.add(formater.parse("23:59"));
        } else {
          OFF.add(off);
        }
      } catch (ParseException e) {
        e.printStackTrace();
      }
      current += Hour_I * 60 + Hour_W * 60 + Min_I + Min_W;
    }

    formater = new SimpleDateFormat("HH:mm:ss");
    Date now = new Date();
    try {
      now = formater.parse(formater.format(now));
    } catch (ParseException e) {
      e.printStackTrace();
    } // on récupère uniquement les heures et les minutes et les secondes
    for (int i = 0; i < ON.size() - 1; i++) {
      if (now.after(ON.get(i)) && now.before(OFF.get(i))) {
        return true;
      }
    }
    return false;
  }
Ejemplo n.º 8
0
  /**
   * Retrieve information about an Catalog. Check if the returned data are equal to the data of
   * create or update call
   *
   * @param isAlreadyUpdated if true check against update data, else against create data
   */
  public void testGetInfo(boolean isAlreadyUpdated) {
    TGetInfo_Return[] Catalogs_out =
        catalogService.getInfo(
            new String[] {full}, new String[] {"Date"}, new String[] {"de", "en"});

    // test if getinfo was successful and if all data are equal to input
    assertEquals("getInfo result set", 1, Catalogs_out.length);
    assertEquals("catalog alias", alias, Catalogs_out[0].getAlias());
    assertEquals("Number of languages", 2, Catalogs_out[0].getName().length);
    HashMap<String, String> hash = new HashMap<String, String>();
    hash.put(
        Catalogs_out[0].getName()[0].getLanguageCode(), Catalogs_out[0].getName()[0].getValue());
    hash.put(
        Catalogs_out[0].getName()[1].getLanguageCode(), Catalogs_out[0].getName()[1].getValue());

    if (isAlreadyUpdated) {

      try {
        Date date_in = sdf_in.parse(Catalog_up.getAttributes()[0].getValue());
        Date date_out = sdf_out.parse(Catalogs_out[0].getAttributes()[0].getValue());
        assertEquals("Date", date_in, date_out);
      } catch (ParseException e) {
        e.printStackTrace();
      }

      assertEquals(
          "updated localized Name",
          Catalog_up.getName()[0].getValue(),
          hash.get(Catalog_up.getName()[0].getLanguageCode()));
      assertEquals(
          "updated localized Name",
          Catalog_up.getName()[1].getValue(),
          hash.get(Catalog_up.getName()[1].getLanguageCode()));
    } else {

      try {
        Date date_in = sdf_in.parse(Catalog_in.getAttributes()[0].getValue());
        Date date_out = sdf_out.parse(Catalogs_out[0].getAttributes()[0].getValue());
        assertEquals("Date", date_in, date_out);
      } catch (ParseException e) {
        e.printStackTrace();
      }

      assertEquals(
          "initial localized Name",
          Catalog_in.getName()[0].getValue(),
          hash.get(Catalog_up.getName()[0].getLanguageCode()));
      assertEquals(
          "initial localized Name",
          Catalog_in.getName()[1].getValue(),
          hash.get(Catalog_up.getName()[1].getLanguageCode()));
    }

    assertThat(Catalogs_out[0].getParentCatalog(), endsWith(Catalog_in.getParentCatalog()));
    assertEquals("IsVisible", Catalog_in.getIsVisible(), Catalogs_out[0].getIsVisible());
  }
 // 设置单元格的值
 @Override
 public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
   TShopCharge tShopCharge = tShopChargeList.get(rowIndex);
   if (tShopCharge != null && aValue != null) {
     switch (columnIndex) {
       case 0:
         break;
       case 1:
         tShopCharge.setSelect(!tShopCharge.isSelect());
         return;
       case 2:
         if (aValue != null
             && !aValue.toString().equals("")
             && MatcherFormatUtil.MatcherPriceScheme(aValue.toString())
             && aValue.toString().length() < 10) {
           tShopCharge.setAMount(Double.parseDouble(aValue.toString()));
         }
         break;
       case 3:
         if (aValue != null
             && !aValue.toString().equals("")
             && MatcherFormatUtil.MatcherPriceScheme(aValue.toString())
             && aValue.toString().length() < 10) {
           tShopCharge.setGiftAmount(Double.parseDouble(aValue.toString()));
         }
         break;
       case 4:
         tShopCharge.setType(aValue.toString());
         break;
       case 5:
         return;
       case 6:
         tShopCharge.setStartTimeStr(aValue.toString());
         try {
           tShopCharge.setStartTime(DateUtil.getDate(aValue.toString(), DateUtil.TYPE_DATE));
         } catch (ParseException e) {
           e.printStackTrace();
         }
         break;
       case 7:
         tShopCharge.setEndTimeStr(aValue.toString());
         try {
           tShopCharge.setEndTime(DateUtil.getDate(aValue.toString(), DateUtil.TYPE_DATE));
         } catch (ParseException e) {
           e.printStackTrace();
         }
         break;
       case 9:
         tShopCharge.setIsValid(!tShopCharge.isIsValid());
         break;
     }
     tShopCharge.setSelect(true);
     fireTableCellUpdated(rowIndex, 1);
   }
 }
  public ArrayList<Contest> parse() {
    ArrayList<Contest> contests = new ArrayList<>();
    String s = Utils.URLToString(contestsPage(), "UTF-8");
    if (s == null) return null;

    try {
      int i = s.indexOf("\"champ\""), p, k, b;
      String t;
      i = s.indexOf("\"name\"", i);
      i = s.indexOf(':', i);
      i = s.indexOf('\"', i);
      String name = s.substring(i + 1, s.indexOf('\"', i + 1));
      i = s.indexOf("\"rounds\"");
      for (; ; ) {
        i = s.indexOf("\"name\"", i + 1);
        if (i == -1) break;
        b = s.lastIndexOf('{', i);
        k = s.indexOf(':', i);
        k = s.indexOf('\"', k);
        Contest c = new Contest();
        String z = s.substring(k + 1, s.indexOf('\"', k + 1));
        c.title = name + " " + z;
        k = s.indexOf("\"start_date\"", b);
        k = s.indexOf(':', k);
        k = s.indexOf('\"', k);
        t = s.substring(k + 1, s.indexOf('\"', k + 1));
        p = t.indexOf('T');
        t = t.substring(0, p) + " " + t.substring(p + 1, p + 9) + " GMT" + t.substring(p + 9);
        try {
          c.startDate.setTime(dateFormat.parse(t));
        } catch (ParseException e) {
          e.printStackTrace();
        }
        k = s.indexOf("\"end_date\"", b);
        k = s.indexOf(':', k);
        k = s.indexOf('\"', k);
        t = s.substring(k + 1, s.indexOf('\"', k + 1));
        p = t.indexOf('T');
        t = t.substring(0, p) + " " + t.substring(p + 1, p + 9) + " GMT" + t.substring(p + 9);
        try {
          c.endDate.setTime(dateFormat.parse(t));
        } catch (ParseException e) {
          e.printStackTrace();
        }
        c.mainPage = mainPage();
        c.deadLine = Utils.timeConsts.YEAR;
        c.icon = getIcon();
        contests.add(c);
      }
    } catch (Exception e) {
      e.printStackTrace();
    }

    return contests;
  }
 public void handleAstronomyAttributes(Attributes attributes) {
   try {
     weatherRecord.sunrise = parseTime(attributes.getValue("sunrise"));
   } catch (ParseException e) {
     e.printStackTrace();
   }
   try {
     weatherRecord.sunset = parseTime(attributes.getValue("sunset"));
   } catch (ParseException e) {
     e.printStackTrace();
   }
 }
  @Override
  @SuppressWarnings("unchecked")
  public List<ApplicationSummary> findApplicationSummaries(Integer curPage, final String q) {
    String sql =
        "select distinct appl.APPL_NO,idcard.NAME,idcard.ID_NO,appl.EXISTING_FLAG,appl.APPLY_TIME,ma.CITY,appl.STATUS,apv.CREDITOR,appl.CREATE_TIME\n"
            + " from APPL appl\n"
            + " inner join APPROVAL apv on apv.APPL_NO = appl.APPL_NO\n"
            + " inner join MEMBER mem on mem.ID = appl.MEMBER_ID\n"
            + " inner join ID_CARD idcard on idcard.MEMBER_ID = mem.ID\n"
            + " inner join VALUE_MOBILE_AREA ma on ma.N1_7 = SUBSTRING(mem.MOBILE,0,8)\n"
            + " left join APPL_TV appltv on appltv.APPL_NO = appl.APPL_NO\n"
            + " left join (select appl.APPL_NO,count(teletv.ID) as NUM from APPL appl,tele_tv teletv where appl.APPL_NO = teletv.APPL_NO group by appl.APPL_NO) as t1 on t1.APPL_NO = appl.APPL_NO\n"
            + " where "
            + q;
    List<Object> resultList =
        em.createNativeQuery(sql)
            .setMaxResults(CommonDef.PER_PAGE)
            .setFirstResult((curPage - 1) * CommonDef.PER_PAGE)
            .getResultList();

    if (resultList == null || resultList.isEmpty()) {
      return null;
    }
    List<ApplicationSummary> applicationSummaryList = new ArrayList<ApplicationSummary>();
    ApplicationSummary applicationSummary = null;
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
    for (Object aResultList : resultList) {
      Object[] objs = (Object[]) aResultList;
      applicationSummary = new ApplicationSummary();
      applicationSummary.setAppNo(objs[0].toString());
      applicationSummary.setName(objs[1].toString());
      applicationSummary.setIdCardNo(objs[2].toString());
      applicationSummary.setExistingFlag(Integer.valueOf(objs[3].toString()));
      applicationSummary.setMobileCity(objs[5].toString());
      applicationSummary.setStatus(Integer.valueOf(objs[6].toString()));
      applicationSummary.setCreditor(objs[7].toString());
      try {
        Date appDate = simpleDateFormat.parse(objs[4].toString());
        applicationSummary.setApplyDate(appDate);
      } catch (ParseException e) {
        e.printStackTrace();
      }
      try {
        Date createDate = simpleDateFormat.parse(objs[8].toString());
        applicationSummary.setCreateDate(createDate);
      } catch (ParseException e) {
        e.printStackTrace();
      }
      applicationSummaryList.add(applicationSummary);
    }
    return applicationSummaryList;
  }
Ejemplo n.º 13
0
  @RequestMapping(value = "/get/{type}", method = RequestMethod.GET)
  public String getPaymentsSpecific(
      ModelMap model,
      @PathVariable String type,
      @RequestParam(required = false, defaultValue = "") String dateFrom,
      @RequestParam(required = false, defaultValue = "") String dateTo,
      @RequestParam(required = false, defaultValue = "") String clientStr) {

    List<Payment> payments = new ArrayList<>();

    SimpleDateFormat sdf = new SimpleDateFormat("yyyyy-MM-dd");
    Date d1 = new Date();
    Date d2 = new Date();

    model
        .addAttribute("dateFrom", dateFrom)
        .addAttribute("dateTo", dateTo)
        .addAttribute("clientStr", clientStr);

    if (type.equals("in")) {

      if (!dateFrom.equals("") && !dateTo.equals("")) {
        try {
          d1 = sdf.parse(dateFrom);
          d2 = sdf.parse(dateTo);
        } catch (ParseException e) {
          e.printStackTrace();
        }
        payments = paymentService.listPayments(clientStr, d1, d2);
      }

      if (dateFrom.equals("") && dateTo.equals("") && !clientStr.equals("")) {
        try {
          d1 = sdf.parse("1971-01-01");
          d2 = sdf.parse("2025-01-01");
        } catch (ParseException e) {
          e.printStackTrace();
        }
        payments = paymentService.listPayments(clientStr, d1, d2);
      }

      if (dateFrom.equals("") && dateTo.equals("") && clientStr.equals("")) {
        payments = paymentService.listPayments();
      }
      model.addAttribute("payments", payments);
      return "/auth/payment/paymentgetin";
    }

    // model.addAttribute("payments", paymentService.listPayments());
    return "/auth/payment/paymentget";
  }
Ejemplo n.º 14
0
  public static void main(String args[]) {

    TimeZone.setDefault(TimeZone.getTimeZone("America/Bogota"));

    DateTime dt = new DateTime();
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    //		System.out.println("- " + sdf.format(dt.toDate()));
    //		sdf.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
    //		System.out.println("- " + sdf.format(dt.toDate()));

    String sd = "2011-03-18 16:30:39";
    sdf.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
    Date d = null;
    try {
      d = sdf.parse(sd);
    } catch (ParseException e) {
      e.printStackTrace();
    }
    System.out.println("- " + sdf.format(d));
    sdf.setTimeZone(TimeZone.getTimeZone("America/Bogota"));
    System.out.println("- " + sdf.format(d));

    try {
      d = sdf.parse(sd);
    } catch (ParseException e) {
      e.printStackTrace();
    }
    System.out.println("- " + sdf.format(d));

    DateTime nDt = dt.withZone(DateTimeZone.forTimeZone(TimeZone.getTimeZone("Asia/Shanghai")));
    System.out.println(sdf.format(nDt.toDate()));

    DateTime dt2 = new DateTime(DateTimeZone.forTimeZone(TimeZone.getTimeZone("Asia/Tokyo")));

    sdf.setTimeZone(TimeZone.getTimeZone("America/Bogota"));
    System.out.println(sdf.format(dt2.toDate()));

    //		System.out.println(getFormatedDateString(""));
    //		System.out.println(getFormatedDateString("America/Bogota"));
    //
    //		//printSysProperties();
    //
    //		System.out.println("------------------------------------------");
    ////		System.setProperty("user.timezone", "America/Bogota");
    //		TimeZone.setDefault(TimeZone.getTimeZone("America/Bogota"));
    //
    //		System.out.println(getFormatedDateString(""));
    //		System.out.println(getFormatedDateString("Asia/Shanghai"));

    // printSysProperties();
  }
Ejemplo n.º 15
0
  public static Date getGuDongDate(String str) {
    str = StringUtils.replace(str, " ", "");
    str = StringUtils.replace(str, "十五", "15");
    str = StringUtils.replace(str, "3月中旬", "3月15日");
    str = StringUtils.replace(str, "2月十五日", "2月15日");
    str = StringUtils.replace(str, "2月中旬", "2月15日");
    str = StringUtils.replace(str, "一月29日", "1月29日");
    str = StringUtils.replace(str, "1月末", "1月29日");
    str = StringUtils.replace(str, "2.29", "2月29日");

    {
      Pattern pattern = Pattern.compile("[0-9]{4}年[0-9]{1,}月[0-9]{1,}日");
      Matcher matcher = pattern.matcher(str);
      String value = "";

      while (matcher.find()) {
        value = (matcher.group());
      }
      // System.out.println("value:"+value);
      if (StringUtils.isNotBlank(value)) {
        String patterns[] = new String[] {"yyyy年M月d日"};
        try {
          Date date = (DateUtils.parseDate(value, patterns));
          return date;
        } catch (ParseException e) {
          e.printStackTrace();
        }
      }
    }

    {
      Pattern pattern = Pattern.compile("([0-9]{1,}月[0-9]{1,}日)");
      Matcher matcher = pattern.matcher(str);
      String value = "";
      while (matcher.find()) {
        value = (matcher.group());
      }
      // System.out.println("value222:"+value);
      if (StringUtils.isNotBlank(value)) {
        String patterns[] = new String[] {"M月d日"};
        try {
          Date date = (DateUtils.parseDate(value, patterns));
          return DateUtils.setYears(date, 2016);
        } catch (ParseException e) {
          e.printStackTrace();
        }
      }
    }
    return null;
  }
 @Override
 public void onLoadFinished(Loader<Cursor> cursorLoader, Cursor cursor) {
   final int lid = cursorLoader.getId();
   switch (lid) {
     case PriorityLoaderId:
       adPriority.swapCursor(cursor);
       getSupportLoaderManager().initLoader(StatusLoaderId, null, this);
       return;
     case StatusLoaderId:
       adStatus.swapCursor(cursor);
       if (id != null) {
         getSupportLoaderManager().initLoader(ItemLoaderId, null, this);
       }
       return;
     case ItemLoaderId:
       if (cursor.moveToFirst()) {
         setTitle(R.string.ui_edit_item);
         edName.setText(cursor.getString(0));
         edDesc.setText(cursor.getString(1));
         SetupSpinner(cursor.getInt(2), sPriority);
         SetupSpinner(cursor.getInt(3), sStatus);
         String time = cursor.getString(4);
         Calendar cal = Calendar.getInstance();
         try {
           cal.setTime(sdf.parse(time));
         } catch (ParseException e) {
           e.printStackTrace();
         }
         tStartDate.setTag(cal);
         tStartDate.setText(sdfdate.format(cal.getTime()));
         tStartTime.setTag(cal);
         tStartTime.setText(sdftime.format(cal.getTime()));
         time = cursor.getString(5);
         cal = Calendar.getInstance();
         try {
           cal.setTime(sdf.parse(time));
         } catch (ParseException e) {
           e.printStackTrace();
         }
         tEndDate.setTag(cal);
         tEndDate.setText(sdfdate.format(cal.getTime()));
         tEndTime.setTag(cal);
         tEndTime.setText(sdftime.format(cal.getTime()));
       } else {
         finish();
       }
       return;
     default:
   }
 }
  @Override
  public void endElement(String uri, String localName, String qName) throws SAXException {
    super.endElement(uri, localName, qName);

    if (localName.equals("item")) {
      stories.add(story);
      story = null;
      largestImgWidth = 0;
    }
    if (story != null) {
      if (localName.equals("title")) {
        story.setTitle(xmlInnerText.toString().trim());
      } else if (localName.equals("description")) {
        story.setDescription(xmlInnerText.toString().trim());
      } else if (localName.equals("link")) {
        story.setLink(xmlInnerText.toString().trim());
      } else if (localName.equals("pubDate")) {
        SimpleDateFormat dtSourceFormat = story.getSourceDateFormater();
        SimpleDateFormat dtTargetFormat = story.getTargetDateFormater();

        try {
          story.setPubDate(dtSourceFormat.parse(xmlInnerText.toString().trim()));
        } catch (ParseException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }

        Log.d("Exam01", "Parsed date : " + dtTargetFormat.format(story.getPubDate()));
      }
      xmlInnerText.setLength(0);
    }
  }
Ejemplo n.º 18
0
 public Date getCellDateValue(HSSFRow row, int index) throws ClearingException {
   HSSFCell cell = row.getCell(index);
   Date date = new Date();
   if (cell == null) {
     return null;
   }
   int cellType = cell.getCellType();
   if (cellType == HSSFCell.CELL_TYPE_NUMERIC) {
     NumberFormat integerInstance = NumberFormat.getInstance();
     integerInstance.setGroupingUsed(false);
     String cellStr = integerInstance.format(cell.getNumericCellValue());
     try {
       date = new SimpleDateFormat("yyyyMMdd").parse(cellStr);
     } catch (ParseException e) {
       throw new ClearingException("日期格式化错误");
     }
     return date;
   } else if (cellType == HSSFCell.CELL_TYPE_STRING) {
     try {
       date = new SimpleDateFormat("yyyyMMdd").parse(cell.getRichStringCellValue().getString());
     } catch (ParseException e) {
       e.printStackTrace();
     }
     return date;
   } else {
     return null;
   }
 }
    @Override
    public void mouseClicked(java.awt.event.MouseEvent e) {
      if (e.getClickCount() == 2) {
        int linha = table.getSelectedRow();
        Evento evento = new Evento();
        evento.setId((int) table.getValueAt(linha, 0));
        evento.setNome((String) table.getValueAt(linha, 1));
        try {
          Moeda moeda = new Moeda((String) table.getValueAt(linha, 2));
          evento.setValor(moeda.getValor());
        } catch (ParseException ex) {
          ex.printStackTrace();
        }

        evento.setDataEvento(
            AppDate.formatarDataInternacional((String) table.getValueAt(linha, 3)));
        eventos.add(evento);

        String nomeEvento, dataEvento, precoEvento;
        nomeEvento = (String) table.getValueAt(linha, 1);
        precoEvento = (String) table.getValueAt(linha, 2);
        dataEvento = (String) table.getValueAt(linha, 3);
        atualizarValor(precoEvento);

        adicionarProdutoVendaList(nomeEvento, precoEvento, dataEvento);
      }
    }
Ejemplo n.º 20
0
 @Override
 public int Add() { // 增加资产
   Class_ManageDao cm = new Class_ManageDaoImpl();
   Scanner input = new Scanner(System.in);
   // 向资产表中添加数据
   System.out.println("请输入要增加的资产name");
   String name = input.next();
   System.out.println("请输入要增加的资产mainclass");
   String mainclass = input.next();
   System.out.println("请输入要增加的资产model");
   String model = input.next();
   System.out.println("请输入要增加的资产value");
   int value = input.nextInt();
   System.out.println("请输入要增加的资产date");
   String date = input.next();
   System.out.println("请输入要增加的资产status");
   int status = input.nextInt();
   SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
   try {
     Date Occ_Date = sdf.parse(date);
   } catch (ParseException e) {
     e.printStackTrace();
   }
   String sql =
       "insert into Fixed_Assets (Assets_name,MainClass,Model,Value,Buy_date,Status) values (?,?,?,?,?,?)";
   Object[] param = {name, mainclass, model, value, date, status};
   int result = this.exceuteUpdate(sql, param);
   // 检查类表中是否有该大类,没有则添加
   // 有该大类时,函数返回true,否则返回false
   if (!cm.getByClassName(mainclass)) {
     cm.Add(mainclass);
   }
   return result;
 }
  // Load stored ToDoItems
  private void loadItems() {
    BufferedReader reader = null;
    try {
      FileInputStream fis = openFileInput(FILE_NAME);
      reader = new BufferedReader(new InputStreamReader(fis));

      String title = null;
      String priority = null;
      String status = null;
      Date date = null;

      while (null != (title = reader.readLine())) {
        priority = reader.readLine();
        status = reader.readLine();
        date = ToDoItem.FORMAT.parse(reader.readLine());
        mAdapter.add(new ToDoItem(title, Priority.valueOf(priority), Status.valueOf(status), date));
      }

    } catch (FileNotFoundException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    } catch (ParseException e) {
      e.printStackTrace();
    } finally {
      if (null != reader) {
        try {
          reader.close();
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
    }
  }
  @Override
  public void onBindViewHolder(ViewHolder viewHolder, int position) {
    // MyListItem myListItem = MyListItem.fromCursor(cursor);
    try {
      SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy", Locale.US);
      viewHolder.seperator.setText(messages.get(position)[1]);
      if (!updatedT
          && parseDate(messages.get(position)[1])
              .equals(parseDate(dateFormat.format(new Date())))) {
        viewHolder.seperator.setVisibility(View.VISIBLE);
        viewHolder.seperator.setText("TODAY");
        updatedT = true;
      } else if (!updatedY
          && parseDate(messages.get(position)[1]).equals(parseDate(getYesterdayDateString()))) {
        viewHolder.seperator.setVisibility(View.VISIBLE);
        viewHolder.seperator.setText("YESTERDAY");
        updatedY = true;
      } else {
        if (lastDate != null && !lastDate.equals(messages.get(position)[1])) {
          viewHolder.seperator.setVisibility(View.VISIBLE);
          viewHolder.seperator.setText(messages.get(position)[1]);
        }
      }

    } catch (java.text.ParseException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    viewHolder.messageSender.setText(
        messages.get(position)[2] + " (time:" + messages.get(position)[1] + ")");
    viewHolder.messageReciever.setText(
        messages.get(position)[5] + " (time:" + messages.get(position)[4] + ")");

    lastDate = messages.get(position)[1];
  }
Ejemplo n.º 23
0
  @AfterViews
  public void setPreferences() {

    SharedPreferences preferences =
        getActivity().getSharedPreferences("CurrentUser", Context.MODE_PRIVATE);

    accessToken = preferences.getString("access_token", "").replace("\"", "");
    if (getArguments() != null) {
      Todo todo = (Todo) getArguments().getSerializable(NEW_INSTANCE_TODO_KEY);
      concernedMembers.addAll(todo.members);
      currentTodoId = todo.id;
      todoInput.setText(todo.text);
      SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
      format.setTimeZone(TimeZone.getTimeZone("UTC"));
      Date date = new Date();
      try {
        date = format.parse(todo.remindMeAt);
      } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
      Calendar cal = Calendar.getInstance();
      TimeZone tz = cal.getTimeZone();
      SimpleDateFormat formatToShow = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
      formatToShow.setTimeZone(tz);

      String[] splitDate = formatToShow.format(date).split(" ");
      dateText.setText(splitDate[0]);
      timeText.setText(splitDate[1]);
    }
  }
  /**
   * Read location information from image.
   *
   * @param imagePath : image absolute path
   * @return : loation information
   */
  public Location readGeoTagImage(String imagePath) {
    Location loc = new Location("");
    try {
      ExifInterface exif = new ExifInterface(imagePath);
      float[] latlong = new float[2];
      if (exif.getLatLong(latlong)) {
        loc.setLatitude(latlong[0]);
        loc.setLongitude(latlong[1]);
      }
      String date = exif.getAttribute(ExifInterface.TAG_DATETIME);
      SimpleDateFormat fmt_Exif = new SimpleDateFormat("yyyy:MM:dd HH:mm:ss");
      try {
        loc.setTime(fmt_Exif.parse(date).getTime());
      } catch (java.text.ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }

    } catch (IOException e) {
      e.printStackTrace();
    } catch (ParseException e) {
      e.printStackTrace();
    }
    return loc;
  }
Ejemplo n.º 25
0
  public void parseStatusXml(String statusXml) {
    try {
      Document statusDoc = SubmissionUtils.emptyDocument();
      SubmissionUtils.transform(new StringReader(statusXml), statusDoc);

      if (statusDoc.getDocumentElement().getTagName().equals("error")) {
        String runName = statusDoc.getElementsByTagName("RunName").item(0).getTextContent();
        String runDirRegex = "(\\d{6})_([A-z0-9]+)_(\\d+)_[A-z0-9_]*";
        Matcher m = Pattern.compile(runDirRegex).matcher(runName);
        if (m.matches()) {
          setStartDate(new SimpleDateFormat("yyMMdd").parse(m.group(1)));
          setInstrumentName(m.group(2));
        }
        setRunName(runName);
        setHealth(HealthType.Unknown);
      } else {
        String runStarted = statusDoc.getElementsByTagName("RunStarted").item(0).getTextContent();
        setStartDate(new SimpleDateFormat("EEEE, MMMMM dd, yyyy h:mm aaa").parse(runStarted));
        setInstrumentName(
            statusDoc.getElementsByTagName("InstrumentName").item(0).getTextContent());
        setRunName(statusDoc.getElementsByTagName("RunName").item(0).getTextContent());
        setHealth(HealthType.Unknown);
      }
      setXml(statusXml);
    } catch (ParserConfigurationException e) {
      e.printStackTrace();
    } catch (TransformerException e) {
      e.printStackTrace();
    } catch (ParseException e) {
      e.printStackTrace();
    }
  }
Ejemplo n.º 26
0
  private JSONObject castEventToJSONObj(Event event) {
    JSONObject jsonObj = new JSONObject();

    DateFormat dfDeadline = new SimpleDateFormat("yyyy-M-dd");
    Date deadLine = null;

    try {
      deadLine = dfDeadline.parse("1970-01-01");
    } catch (ParseException e) {
      e.printStackTrace();
    }

    try {
      jsonObj.put("name", event.getName());
      jsonObj.put("description", event.getDescription());
      jsonObj.put("category", event.getCategory());
      jsonObj.put("status", event.getStatus());
      jsonObj.put("location", event.getLocation());

      if (event.getCategory().equals(GenericEvent.Category.DEADLINE)) {
        jsonObj.put("startTime", deadLine);
        jsonObj.put("endTime", event.getEndTime());
      } else {
        jsonObj.put("startTime", event.getStartTime());
        jsonObj.put("endTime", event.getEndTime());
      }
    } catch (JSONException e) {
      e.printStackTrace();
    }

    return jsonObj;
  }
Ejemplo n.º 27
0
 @Override
 public final int compare(String[] o1, String[] o2) {
   String t1 = o1[this.index];
   String t2 = o2[this.index];
   if (StringUtils.isEmpty(t1) && StringUtils.isEmpty(t2)) {
     return 0;
   }
   if (StringUtils.isEmpty(t1)) {
     return 1;
   }
   if (StringUtils.isEmpty(t2)) {
     return -1;
   }
   if (StringUtils.isNumeric(t1) && StringUtils.isNumeric(t2)) {
     // 数値文字列の場合
     Long o1l = Long.valueOf(t1);
     Long o2l = Long.valueOf(t2);
     return this.compareTo(o1l, o2l, this.order);
   } else if (t1.matches("(?:\\d+日)?(?:\\d+時間)?(?:\\d+分)?(?:\\d+秒)?")) {
     try {
       // 時刻文字列の場合
       // SimpleDateFormatは24時間超えるような時刻でも正しく?パースしてくれる
       Date o1date = DateUtils.parseDate(t1, "ss秒", "mm分ss秒", "HH時間mm分", "dd日HH時間mm分");
       Date o2date = DateUtils.parseDate(t2, "ss秒", "mm分ss秒", "HH時間mm分", "dd日HH時間mm分");
       return this.compareTo(o1date, o2date, this.order);
     } catch (ParseException e) {
       e.printStackTrace();
     }
   }
   // 文字列の場合
   return this.compareTo(t1, t2, this.order);
 }
Ejemplo n.º 28
0
  public void query(String tableName, List<IGame> games) {
    Cursor c = queryTheCursor2(tableName);
    while (c.moveToNext()) {
      IGame game;
      int _id = c.getInt(c.getColumnIndex("_id"));
      String guest = c.getString(c.getColumnIndex("guest"));
      String host = c.getString(c.getColumnIndex("host"));
      int type = c.getInt(c.getColumnIndex("type"));
      String chanls = c.getString(c.getColumnIndex("chanls"));
      Boolean isEvent = (c.getInt(c.getColumnIndex("evented")) != 0);
      Long eventId = c.getLong(c.getColumnIndex("eventid"));
      String originalString = c.getString(c.getColumnIndex("dt"));
      Date dt;
      try {
        Date tmpDt = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.US).parse(originalString);
        dt = tmpDt;

        if (tableName.equals("azhibogame"))
          game = new AzhiboGame(_id, guest, host, dt, type, chanls, isEvent, eventId);
        else game = new SinaGame(_id, guest, host, dt, type, chanls, isEvent, eventId);
        games.add(game);
      } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }
    c.close();
  }
Ejemplo n.º 29
0
  public static void main(String[] args) {
    NetCDFDir2Block_Reanalysis ncb = new NetCDFDir2Block_Reanalysis();

    if (args.length != 5) {
      System.out.println(
          "Usage: <input variable name> <input directory> <output directory> <block size> <start time yyyy_MM_dd in UTC>");
      System.exit(-1);
    }

    ncb.inVarName = args[0];
    ncb.fileDir = args[1];
    ncb.outputDir = args[2];
    ncb.blocksize = TimeConvert.daysToMillis(args[3]);
    ncb.filter = new FilenamePatternFilter(".*_" + ncb.inVarName + "_.*\\.nc");
    if (ncb.inVarName.equalsIgnoreCase("w")) {
      ncb.inVarName = "w_velocity";
    }
    if (ncb.inVarName.equalsIgnoreCase("u")) {
      ncb.inVarName = "water_u";
    }
    if (ncb.inVarName.equalsIgnoreCase("v")) {
      ncb.inVarName = "water_v";
    }
    String initString = args[4] + " UTC";
    // String initString = "1993_01_01" + " UTC";

    try {
      // ncb.initialTime = ncb.df2.parse("2014_03_06 UTC").getTime();
      ncb.initialTime = ncb.df2.parse(initString).getTime();
    } catch (ParseException e) {
      e.printStackTrace();
    }
    ncb.convert(ncb.fileDir, ncb.filter, ncb.blocksize);
    System.out.println("Complete.");
  }
Ejemplo n.º 30
0
  public List<IGame> query(List<IGame> games) {
    Cursor c = queryTheCursor();
    while (c.moveToNext()) {
      SinaGame game = new SinaGame();
      game._id = c.getInt(c.getColumnIndex("_id"));
      game.guest = c.getString(c.getColumnIndex("guest"));
      game.host = c.getString(c.getColumnIndex("host"));
      game.type = c.getInt(c.getColumnIndex("type"));
      game.chanls = c.getString(c.getColumnIndex("chanls"));
      game.isEvent = (c.getInt(c.getColumnIndex("evented")) != 0);
      game.eventId = c.getLong(c.getColumnIndex("eventid"));

      String originalString = c.getString(c.getColumnIndex("dt"));
      Date date;
      try {
        date = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.US).parse(originalString);
        game.dt = date;
      } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
      games.add(game);
    }
    c.close();
    return games;
  }