java.text.ParseException Java Examples

The following examples show how to use java.text.ParseException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DateUtils.java    From danyuan-application with Apache License 2.0 6 votes vote down vote up
/**
 * 从日期FROM到日期TO的天数
 *
 * @param dateStrFrom
 *            日期FROM("yyyy-MM-dd")
 * @param dateStrTo
 *            日期TO("yyyy-MM-dd")
 * @author 2015/06/11 Jinhui
 * @return int 天数
 */
public static int getDaysIn2Day(String dateStrFrom, String dateStrTo) {
	
	if (StringUtils.isEmpty(dateStrFrom) || StringUtils.isEmpty(dateStrTo)) {
		return 0;
	}
	
	SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
	Calendar fromCalendar = Calendar.getInstance();
	Calendar toCalendar = Calendar.getInstance();
	try {
		fromCalendar.setTime(sdf.parse(dateStrFrom.trim()));
		toCalendar.setTime(sdf.parse(dateStrTo.trim()));
	} catch (ParseException ex) {
		throw new RuntimeException(ex);
	}
	long day = (toCalendar.getTime().getTime() - fromCalendar.getTime().getTime()) / (24 * 60 * 60 * 1000);
	
	return ConvUtils.convToInt(day);
}
 
Example #2
Source File: NumberTextField.java    From mars-sim with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Tries to parse the user input to a number according to the provided
 * NumberFormat
 */
private void parseAndFormatInput() {
    try {
        String input = getText();
        if (input == null || input.length() == 0) {
            return;
        }
        Number parsedNumber = nf.parse(input);
        BigDecimal newValue = new BigDecimal(parsedNumber.toString());
        setNumber(newValue);
        selectAll();
    } catch (ParseException ex) {
        // If parsing fails keep old number
        setText(nf.format(number.get()));
    }
}
 
Example #3
Source File: WebScriptUtil.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static Date getDate(JSONObject json) throws ParseException
{
    if(json == null)
    {
        return null;
    }
    String dateTime = json.optString(DATE_TIME);
    if(dateTime == null)
    {
        return null;
    }
    String format = json.optString(FORMAT);
    if(format!= null && ISO8601.equals(format) == false)
    {
        SimpleDateFormat dateFormat = new SimpleDateFormat(format);
        return dateFormat.parse(dateTime);
    }
    return ISO8601DateFormat.parse(dateTime);
}
 
Example #4
Source File: PublicApiClient.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 6 votes vote down vote up
public AuditEntry getAuditEntry(String applicationId, String entryId, Map<String, String> param, int expectedStatus)
        throws PublicApiException, ParseException
{
    HttpResponse response = getSingle("audit-applications", applicationId, "audit-entries",entryId,
            param, "Failed to get Audit Application " + applicationId, expectedStatus);

    if (response != null && response.getJsonResponse() != null)
    {
        JSONObject jsonList = (JSONObject) response.getJsonResponse().get("entry");
        if (jsonList != null)
        {
            return AuditEntry.parseAuditEntry(jsonList);
        }
    }
    return null;
}
 
Example #5
Source File: HexValue4Field.java    From zxpoly with GNU General Public License v3.0 6 votes vote down vote up
public HexValue4Field() {
  super();
  final JFormattedTextField.AbstractFormatter FORMAT;
  try {
    final MaskFormatter formatter = new MaskFormatter("HHHH");
    formatter.setPlaceholderCharacter('0');
    formatter.setValidCharacters(ALLOWED_CHARS);
    formatter.setAllowsInvalid(false);
    FORMAT = formatter;
  } catch (ParseException ex) {
    throw new Error("Can't prepare formatter", ex);
  }

  setFormatter(FORMAT);
  refreshTextValue();
}
 
Example #6
Source File: CloudAnalyticsClientTests.java    From azure-storage-android with Apache License 2.0 6 votes vote down vote up
/**
 * Validate Log Parser with prod data
 *
 * @throws ParseException
 * @throws URISyntaxException
 * @throws StorageException
 * @throws IOException
 * @throws InterruptedException
 */
@Test
public void testCloudAnalyticsClientParseProdLogs() throws ParseException, URISyntaxException, StorageException,
        IOException {

    Calendar startTime = new GregorianCalendar();
    startTime.add(GregorianCalendar.HOUR_OF_DAY, -2);

    Iterator<LogRecord> logRecordsIterator = (this.client.listLogRecords(StorageService.BLOB, startTime.getTime(),
            null, null, null)).iterator();

    while (logRecordsIterator.hasNext()) {
        // Makes sure there's no exceptions thrown and that no records are null.
        // Primarily a sanity check.
        LogRecord rec = logRecordsIterator.next();
        System.out.println(rec.getRequestUrl());
        assertNotNull(rec);
    }
}
 
Example #7
Source File: User.java    From pingid-api-playground with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unused")
private Date parseDate(String dateToParse) {

	SimpleDateFormat PingIDDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
	PingIDDateFormat.setTimeZone(TimeZone.getTimeZone("America/Denver"));
	
	if (dateToParse != null) {
		try {
			return PingIDDateFormat.parse(dateToParse);
		} catch (ParseException e) {
			e.printStackTrace();
		}
	}
	
	return null;
}
 
Example #8
Source File: SupplierRevenueShareBuilder.java    From development with Apache License 2.0 6 votes vote down vote up
public RDOSupplierRevenueShareReports buildReports()
        throws ParserConfigurationException, SAXException, IOException,
        XPathExpressionException, ParseException {
    if (sqlData == null || sqlData.isEmpty()) {
        return new RDOSupplierRevenueShareReports();
    }

    RDOSupplierRevenueShareReports result = new RDOSupplierRevenueShareReports();
    result.setEntryNr(idGen.nextValue());
    result.setServerTimeZone(DateConverter.getCurrentTimeZoneAsUTCString());

    for (ReportData data : sqlData) {
        xmlDocument = XMLConverter.convertToDocument(data.getResultXml(),
                false);
        result.getReports().add(build(data, result.getEntryNr()));
    }
    return result;
}
 
Example #9
Source File: ExsltDatetime.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Get the start of zone information if the input ends
 * with 'Z' or +/-hh:mm. If a zone string is not
 * found, return -1; if the zone string is invalid,
 * return -2.
 */
private static int getZoneStart (String datetime)
{
  if (datetime.indexOf("Z") == datetime.length()-1)
    return datetime.length()-1;
  else if (datetime.length() >=6
            && datetime.charAt(datetime.length()-3) == ':'
            && (datetime.charAt(datetime.length()-6) == '+'
                || datetime.charAt(datetime.length()-6) == '-'))
  {
    try
    {
      SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm");
      dateFormat.setLenient(false);
      Date d = dateFormat.parse(datetime.substring(datetime.length() -5));
      return datetime.length()-6;
    }
    catch (ParseException pe)
    {
      System.out.println("ParseException " + pe.getErrorOffset());
      return -2; // Invalid.
    }

  }
    return -1; // No zone information.
}
 
Example #10
Source File: NumberRegressionTests.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * NumberFormat does not parse negative zero.
 */
@Test
public void Test4162852() throws ParseException {
    for (int i=0; i<2; ++i) {
        NumberFormat f = (i == 0) ? NumberFormat.getInstance()
            : NumberFormat.getPercentInstance();
        double d = -0.0;
        String s = f.format(d);
        double e = f.parse(s).doubleValue();
        logln("" +
              d + " -> " +
              '"' + s + '"' + " -> " +
          e);
        if (e != 0.0 || 1.0/e > 0.0) {
            logln("Failed to parse negative zero");
        }
    }
}
 
Example #11
Source File: CourseController.java    From springbootexamples with Apache License 2.0 6 votes vote down vote up
@RequestMapping("/dates")
public String dates(Model model) throws ParseException{
	Date date = new Date();
	model.addAttribute("date",date);
	
	String dateStr = "2018-05-30";
	SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
	Date date2 =  sdf.parse(dateStr); 
	Date[] datesArray = new Date[2];
	datesArray[0] = date;
	datesArray[1] = date2;
	model.addAttribute("datesArray",datesArray);
	
	List<Date> datesList = new ArrayList<Date>();
	datesList.add(date);
	datesList.add(date2);
	model.addAttribute("datesList",datesList);
	return "/course/dates";
}
 
Example #12
Source File: PropertyListParser.java    From Alite with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Parses a property list from a file.
 *
 * @param f The property list file.
 * @return The root object in the property list. This is usually a NSDictionary but can also be a NSArray.
 * @throws javax.xml.parsers.ParserConfigurationException If a document builder for parsing a XML property list
 *                                                        could not be created. This should not occur.
 * @throws java.io.IOException If any IO error occurs while reading the file.
 * @throws org.xml.sax.SAXException If any parse error occurs.
 * @throws com.dd.plist.PropertyListFormatException If the given property list has an invalid format.
 * @throws java.text.ParseException If a date string could not be parsed.
 */
public static NSObject parse(File f) throws IOException, PropertyListFormatException, ParseException, ParserConfigurationException, SAXException {
    FileInputStream fis = new FileInputStream(f);
    int type = determineType(fis);
    fis.close();
    switch(type) {
        case TYPE_BINARY:
            return BinaryPropertyListParser.parse(f);
        case TYPE_XML:
            return XMLPropertyListParser.parse(f);
        case TYPE_ASCII:
            return ASCIIPropertyListParser.parse(f);
        default:
            throw new PropertyListFormatException("The given file is not a property list of a supported format.");
    }
}
 
Example #13
Source File: AppController.java    From cachecloud with Apache License 2.0 6 votes vote down vote up
/**
 * 应用日报查询
 */
@RequestMapping("/daily")
public ModelAndView appDaily(HttpServletRequest request,
                              HttpServletResponse response, Model model, Long appId) throws ParseException {
    // 1. 应用信息
    AppDesc appDesc = appService.getByAppId(appId);
    model.addAttribute("appDesc", appDesc);

    // 2. 日期
    String dailyDateParam = request.getParameter("dailyDate");
    Date date;
    if (StringUtils.isBlank(dailyDateParam)) {
        date = DateUtils.addDays(new Date(), -1);
    } else {
        date = DateUtil.parseYYYY_MM_dd(dailyDateParam);
    }
    model.addAttribute("dailyDate", dailyDateParam);

    // 3. 日报
    AppDailyData appDailyData = appDailyDataCenter.getAppDailyData(appId, date);
    model.addAttribute("appDailyData", appDailyData);

    return new ModelAndView("app/appDaily");
}
 
Example #14
Source File: GMTDateGsonAdapter.java    From YiBo with Apache License 2.0 6 votes vote down vote up
@Override
public Date deserialize(JsonElement json, final Type typeOfT,
		JsonDeserializationContext context) throws JsonParseException {
	if (json.isJsonNull()) {
           return null;
       }
       if (!json.isJsonPrimitive()) {
           throw new JsonParseException("it' not json primitive");
       }
       final JsonPrimitive primitive = (JsonPrimitive) json;
       if (!primitive.isString()) {
           throw new JsonParseException("Expected string for date type");
       }
       try {
       	synchronized (dateFormat) {
               return dateFormat.parse(primitive.getAsString());
		}
       } catch (ParseException e) {
           throw new JsonParseException("Not a date string");
       }
}
 
Example #15
Source File: ExsltDatetime.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Get the start of zone information if the input ends
 * with 'Z' or +/-hh:mm. If a zone string is not
 * found, return -1; if the zone string is invalid,
 * return -2.
 */
private static int getZoneStart (String datetime)
{
  if (datetime.indexOf("Z") == datetime.length()-1)
    return datetime.length()-1;
  else if (datetime.length() >=6
            && datetime.charAt(datetime.length()-3) == ':'
            && (datetime.charAt(datetime.length()-6) == '+'
                || datetime.charAt(datetime.length()-6) == '-'))
  {
    try
    {
      SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm");
      dateFormat.setLenient(false);
      Date d = dateFormat.parse(datetime.substring(datetime.length() -5));
      return datetime.length()-6;
    }
    catch (ParseException pe)
    {
      System.out.println("ParseException " + pe.getErrorOffset());
      return -2; // Invalid.
    }

  }
    return -1; // No zone information.
}
 
Example #16
Source File: MainPanel.java    From java-swing-tips with MIT License 6 votes vote down vote up
private static void createAndShowGui() {
  Class<?> clz = MainPanel.class;
  try (InputStream is = clz.getResourceAsStream("button.xml")) {
    SynthLookAndFeel synth = new SynthLookAndFeel();
    synth.load(is, clz);
    UIManager.setLookAndFeel(synth);
  } catch (IOException | ParseException | UnsupportedLookAndFeelException ex) {
    ex.printStackTrace();
    Toolkit.getDefaultToolkit().beep();
  }
  // try {
  //   SynthLookAndFeel synth = new SynthLookAndFeel();
  //   synth.load(clz.getResource("button.xml"));
  //   UIManager.setLookAndFeel(synth);
  // } catch (IOException | ParseException | UnsupportedLookAndFeelException ex) {
  //   ex.printStackTrace();
  // }
  JFrame frame = new JFrame("@title@");
  frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
  frame.getContentPane().add(new MainPanel());
  frame.pack();
  frame.setLocationRelativeTo(null);
  frame.setVisible(true);
}
 
Example #17
Source File: TestVersion.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
public void testParseLenientlyExceptions() {
  ParseException expected = expectThrows(ParseException.class, () -> {
    Version.parseLeniently("LUCENE");
  });
  assertTrue(expected.getMessage().contains("LUCENE"));

  expected = expectThrows(ParseException.class, () -> {
    Version.parseLeniently("LUCENE_610");
  });
  assertTrue(expected.getMessage().contains("LUCENE_610"));

  expected = expectThrows(ParseException.class, () -> {
    Version.parseLeniently("LUCENE61");
  });
  assertTrue(expected.getMessage().contains("LUCENE61"));

  expected = expectThrows(ParseException.class, () -> {
    Version.parseLeniently("LUCENE_7.0.0");
  });
  assertTrue(expected.getMessage().contains("LUCENE_7.0.0"));
}
 
Example #18
Source File: HoodieWriteClient.java    From hudi with Apache License 2.0 6 votes vote down vote up
/**
 * Commit Compaction and track metrics.
 */
protected void completeCompaction(HoodieCommitMetadata metadata, JavaRDD<WriteStatus> writeStatuses, HoodieTable<T> table,
                                  String compactionCommitTime) {

  List<HoodieWriteStat> writeStats = writeStatuses.map(WriteStatus::getStat).collect();
  finalizeWrite(table, compactionCommitTime, writeStats);
  LOG.info("Committing Compaction " + compactionCommitTime + ". Finished with result " + metadata);
  CompactHelpers.completeInflightCompaction(table, compactionCommitTime, metadata);

  if (compactionTimer != null) {
    long durationInMs = metrics.getDurationInMs(compactionTimer.stop());
    try {
      metrics.updateCommitMetrics(HoodieActiveTimeline.COMMIT_FORMATTER.parse(compactionCommitTime).getTime(),
          durationInMs, metadata, HoodieActiveTimeline.COMPACTION_ACTION);
    } catch (ParseException e) {
      throw new HoodieCommitException("Commit time is not of valid format. Failed to commit compaction "
          + config.getBasePath() + " at time " + compactionCommitTime, e);
    }
  }
  LOG.info("Compacted successfully on commit " + compactionCommitTime);
}
 
Example #19
Source File: AttributeTypeDescriptionSchemaParserRelaxedTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Tests without EQUALITY
 * 
 * @throws ParseException
 */
@Test
public void testNoqualityMR() throws ParseException
{
    String value = "( 2.5.4.58 NAME 'attributeCertificateAttribute' " + "DESC 'attribute certificate use ;binary' "
        + "SYNTAX 1.3.6.1.4.1.1466.115.121.1.8 ) ";
    AttributeType attributeType = parser.parse( value );

    assertEquals( "2.5.4.58", attributeType.getOid() );
    assertEquals( 1, attributeType.getNames().size() );
    assertEquals( "attributeCertificateAttribute", attributeType.getNames().get( 0 ) );
    assertEquals( "attribute certificate use ;binary", attributeType.getDescription() );
    assertNull( attributeType.getSuperiorOid() );
    assertNull( attributeType.getEqualityOid() );
    assertEquals( "1.3.6.1.4.1.1466.115.121.1.8", attributeType.getSyntaxOid() );
    assertEquals( UsageEnum.USER_APPLICATIONS, attributeType.getUsage() );
    assertEquals( 0, attributeType.getExtensions().size() );
}
 
Example #20
Source File: TimeUtil.java    From PatatiumAppUi with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 按指定格式格式化时间
 * @param date 字符串日期
 * @param format 格式化表达式
 * @return 返回格式化时间字符串
 */
public  static String formatDate(String date,String format)
{
    SimpleDateFormat sdf = new SimpleDateFormat(format);
    SimpleDateFormat sdf2 = new SimpleDateFormat(format);
    String sss = null;
    try {
        sss = sdf2.format(sdf.parse(date));
        //System.out.println(sss);
    } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return sss;
}
 
Example #21
Source File: DateUtil.java    From framework with Apache License 2.0 5 votes vote down vote up
/**
 * Description: <br>
 * 
 * @author yang.zhipeng <br>
 * @taskId <br>
 * @param date <br>
 * @param format <br>
 * @return <br>
 */
public static Date string2Date(final String date, final String format) {
    if (StringUtils.isEmpty(format)) {
        throw new IllegalArgumentException("the date format string is null!");
    }
    DateFormat sdf = new SimpleDateFormat(format);
    try {
        return sdf.parse(date.trim());
    }
    catch (ParseException e) {
        throw new IllegalArgumentException("the date string " + date + " is not matching format: " + format, e);
    }
}
 
Example #22
Source File: DatePropertyHandler.java    From olat with Apache License 2.0 5 votes vote down vote up
/**
*/
  @Override
  public String getStringValue(final String displayValue, final Locale locale) {
      if (StringHelper.containsNonWhitespace(displayValue)) {
          final DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, locale);
          df.setLenient(false);
          try {
              final Date date = df.parse(displayValue.trim());
              return encode(date);
          } catch (final ParseException e) {
              // catch but do nothing, return null in the end
          }
      }
      return null;
  }
 
Example #23
Source File: NumberToolsTests.java    From ministocks with MIT License 5 votes vote down vote up
@Test
public void trimWithNumberLessThan100AndScale1() throws ParseException {
    // Arrange
    String expected = "12.30";

    // Act
    String result = NumberTools.trim("12.3", Locale.US);

    // Assert
    assertEquals(expected, result);
}
 
Example #24
Source File: Vector3DFormat.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Parses a string to produce a {@link Vector3D} object.
 * @param source the string to parse
 * @return the parsed {@link Vector3D} object.
 * @exception ParseException if the beginning of the specified string
 *            cannot be parsed.
 */
public Vector3D parse(String source) throws ParseException {
    ParsePosition parsePosition = new ParsePosition(0);
    Vector3D result = parse(source, parsePosition);
    if (parsePosition.getIndex() == 0) {
        throw MathRuntimeException.createParseException(
                parsePosition.getErrorIndex(),
                "unparseable 3D vector: \"{0}\"", source);
    }
    return result;
}
 
Example #25
Source File: FuturePresenter.java    From easyweather with MIT License 5 votes vote down vote up
@Override
public void loadData() {
    List<FutureContext> lists = new ArrayList<>();
    HWeather weather = mWeatherRepository.getLocalWeather(mWeatherRepository.getShowCity());
    String[] weeks = new String[0];
    try {
        weeks = DateUtil.
                getNextWeek(new SimpleDateFormat("yyyy-MM-dd").
                        parse(WeatherJsonConverter.getWeather(weather).getDaily_forecast().get(0).getDate()));
    } catch (ParseException e) {
        e.printStackTrace();
    }

    for(int i = 0; i < WeatherJsonConverter.getWeather(weather).getDaily_forecast().size(); i++) {
        FutureContext fc = new FutureContext();
        fc.setCond(WeatherJsonConverter.getWeather(weather).getDaily_forecast().get(i).getCond().getTxt_d());
        fc.setHum(WeatherJsonConverter.getWeather(weather).getDaily_forecast().get(i).getHum());
        fc.setTmp(WeatherJsonConverter.getWeather(weather).getDaily_forecast().get(i).getTmp().getMax() + "°" + "/" +
                WeatherJsonConverter.getWeather(weather).getDaily_forecast().get(i).getTmp().getMin() + "°");

        fc.setWind(WeatherJsonConverter.getWeather(weather).getDaily_forecast().get(i).getWind().getSpd());
        fc.setVis(WeatherJsonConverter.getWeather(weather).getDaily_forecast().get(i).getVis());
        fc.setPop(WeatherJsonConverter.getWeather(weather).getDaily_forecast().get(i).getPop());
        fc.setSunrise(WeatherJsonConverter.getWeather(weather).getDaily_forecast().get(i).getAstro().getSr());
        fc.setSunset(WeatherJsonConverter.getWeather(weather).getDaily_forecast().get(i).getAstro().getSs());
        fc.setPcpn(WeatherJsonConverter.getWeather(weather).getDaily_forecast().get(i).getPcpn());
        fc.setPres(WeatherJsonConverter.getWeather(weather).getDaily_forecast().get(i).getPres());
        fc.setDes(WeatherJsonConverter.getWeather(weather).getDaily_forecast().get(i).getWind().getDir());
        fc.setTime(weeks[i]);
        lists.add(fc);
    }
    mView.showListView(lists);
}
 
Example #26
Source File: RadarDataInventory.java    From tds with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public Date getDate(Path path) {
  Path relPath = base.relativize(path);
  StringBuilder sb = new StringBuilder("");
  for (Integer l : levels) {
    sb.append(relPath.getName(l));
  }
  try {
    SimpleDateFormat fmt = getFormat();
    return fmt.parse(sb.toString());
  } catch (ParseException e) {
    return null;
  }
}
 
Example #27
Source File: LogAnalyzer.java    From reladomo with Apache License 2.0 5 votes vote down vote up
private Date parseDate(String dateStr) throws ParseException
{
    try
    {
        return DATE_FORMAT.parse(dateStr);
    }
    catch(ParseException e)
    {
        // ok, we'll try it again
    }
    return ALTERNATE_FORMAT.parse(dateStr);
}
 
Example #28
Source File: TimestampSerializer.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
public static long dateStringToTimestamp(String source) throws MarshalException
{
    if (source.equalsIgnoreCase("now"))
        return System.currentTimeMillis();

    // Milliseconds since epoch?
    if (timestampPattern.matcher(source).matches())
    {
        try
        {
            return Long.parseLong(source);
        }
        catch (NumberFormatException e)
        {
            throw new MarshalException(String.format("unable to make long (for date) from: '%s'", source), e);
        }
    }

    // Last chance, attempt to parse as date-time string
    try
    {
        return DateUtils.parseDateStrictly(source, dateStringPatterns).getTime();
    }
    catch (ParseException e1)
    {
        throw new MarshalException(String.format("unable to coerce '%s' to a  formatted date (long)", source), e1);
    }
}
 
Example #29
Source File: DateUtils.java    From yyblog with MIT License 5 votes vote down vote up
public static Date calculateDayEndTime(Date date) {
    SimpleDateFormat yyyyMMdd = new SimpleDateFormat("yyyy-MM-dd");
    SimpleDateFormat yyyyMMddHHmmss = new SimpleDateFormat("yyyy-MM-ddHH:mm:ss");
    try {
        return yyyyMMddHHmmss.parse(yyyyMMdd.format(date) + "23:59:59");
    } catch (ParseException e) {
        return null;
    }
}
 
Example #30
Source File: MimeTypeRange.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public static List<MimeTypeRange> parseRanges(String s) throws ParseException {
    StringCutter cutter = new StringCutter(s,true);
    List<MimeTypeRange> r = new ArrayList<MimeTypeRange>();
    while(cutter.length()>0) {
        r.add(new MimeTypeRange(cutter));
    }
    return r;
}