List of usage examples for java.text ParseException toString
public String toString()
From source file:MainClass.java
public static void main(String[] args) throws ParseException { try {//w w w . ja va 2s.c o m SimpleDateFormat formatter = new SimpleDateFormat("yyyy/MM/dd"); String date = "2003/01/10"; java.util.Date utilDate = formatter.parse(date); java.sql.Date sqlDate = new java.sql.Date(utilDate.getTime()); System.out.println("date:" + date); System.out.println("sqlDate:" + sqlDate); } catch (ParseException e) { System.out.println(e.toString()); e.printStackTrace(); } }
From source file:MainClass.java
public static void main(String[] args) throws ParseException { int year = 2003; int month = 12; int day = 12; String date = year + "/" + month + "/" + day; java.util.Date utilDate = null; try {// www . j a va2s . co m SimpleDateFormat formatter = new SimpleDateFormat("yyyy/MM/dd"); utilDate = formatter.parse(date); System.out.println("utilDate:" + utilDate); } catch (ParseException e) { System.out.println(e.toString()); e.printStackTrace(); } }
From source file:org.servalproject.maps.dataman.DataManCli.java
/** * @param args/*from w w w .ja va 2 s . co m*/ */ public static void main(String[] args) { // parse the command line options CommandLineParser parser = new PosixParser(); CommandLine cmd = null; try { cmd = parser.parse(createOptions(), args); } catch (org.apache.commons.cli.ParseException e) { // something bad happened so output help message printCliHelp("Error in parsing arguments:\n" + e.getMessage()); } /* * get and test the command line arguments */ // input path String inputPath = cmd.getOptionValue("input"); if (Utils.isEmpty(inputPath)) { printCliHelp("Error: the path to the input file is required"); } if (Utils.isFileAccessible(inputPath) == false) { printCliHelp("Error: the input file is not accessible"); } File inputFile = new File(inputPath); // output path String outputPath = cmd.getOptionValue("output"); if (Utils.isEmpty(outputPath)) { printCliHelp("Error: the path to the output file is required"); } if (Utils.isFileAccessible(outputPath) == true) { printCliHelp("Error: the output file already exists"); } // create output directory if needed if (outputPath.contains("/")) { int last = outputPath.lastIndexOf("/"); if (last >= 0) { String dir = outputPath.substring(0, last); boolean success = (new File(dir)).mkdirs(); if (!success) { System.err.println("Unable to create directory " + dir); } } } File outputFile = new File(outputPath); // task type String taskType = cmd.getOptionValue("task"); if (Utils.isEmpty(taskType)) { printCliHelp("Error: the task type is required"); } HashMap<String, String> taskTypes = TaskTypes.getTaskTypes(); if (taskTypes.containsKey(taskType) == false) { printCliHelp( "Error: the task type was not recognised.\nKnown task types are:" + TaskTypes.getTaskList()); } // style information String style = cmd.getOptionValue("style"); KmlStyle kmlStyle = null; // expand on the list of styles if (style != null) { try { kmlStyle = new KmlStyle(style); } catch (ParseException e) { System.err.println("unable to parse the style definition\n" + e.toString()); System.exit(-1); } } // verbose output boolean verbose = cmd.hasOption("verbose"); // output info if required if (verbose) { System.out.println(APP_NAME); System.out.println("Version: " + APP_VERSION); System.out.println("More info: " + MORE_INFO + "\n"); System.out.println("License info: " + LICENSE_INFO + "\n"); try { System.out.println("Input file: " + inputFile.getCanonicalPath()); System.out.println("Output file: " + outputFile.getCanonicalPath()); } catch (IOException e) { } System.out.println("Undertaking the task to: " + taskTypes.get(taskType)); } // undertake the specific task if (taskType.startsWith("binloctokml") == true) { LocationsToKml task = new LocationsToKml(inputFile, outputFile, LocationsToKml.BINARY_FILE_TYPE, verbose, kmlStyle); try { task.undertakeTask(taskType); } catch (TaskException e) { System.err.println("Error: Task execution failed\n" + e.toString()); } } }
From source file:Main.java
/** * Parses a string as an opaque color, either as a decimal hue (example: {@code 330}) using a * standard set of saturation and value) or as six digit hex code (example: {@code #BB66FF}). * If the string is null or cannot otherwise be parsed, any error is logged and * {@code defaultColor} is returned./* www . j ava 2 s.c o m*/ * * @param str The input to parse. * @param tempHsvArray An optional previously allocated array for HSV calculations. * @param defaultColor The default color to return if the color cannot be parsed. * @return The parsed color, in {@code int} form. */ public static int parseColor(@Nullable String str, @Nullable float[] tempHsvArray, int defaultColor) { if (str == null) { return defaultColor; } str = str.trim(); if (str.isEmpty()) { return defaultColor; } try { return parseColor(str, tempHsvArray); } catch (ParseException e) { Log.w(TAG, e.toString()); return defaultColor; } }
From source file:com.sudoku.data.model.User.java
public static User buildFromAvroUser(com.sudoku.comm.generated.User user) { User resultUser = new User(); DateFormat df = new SimpleDateFormat("dd/MM/yyyy", Locale.ENGLISH); resultUser.pseudo = user.getPseudo(); resultUser.profilePicturePath = user.getProfilePicturePath(); resultUser.ipAddress = user.getIpAddress(); resultUser.salt = user.getSalt();/*from ww w. ja v a2s . c om*/ try { resultUser.birthDate = df.parse(user.getBirthDate()); resultUser.createDate = df.parse(user.getCreateDate()); resultUser.updateDate = df.parse(user.getUpdateDate()); } catch (ParseException ex) { LOGGER.error(ex.toString()); } resultUser.contactCategories = new LinkedList<>(); // NEED TO SERIALIZE THIS BUT NOT TRANSFER IT return resultUser; }
From source file:com.qhn.bhne.xhmusic.utils.MyUtils.java
/** * from yyyy-MM-dd HH:mm:ss to MM-dd HH:mm *///from w w w .ja v a2s . co m public static String formatDate(String before) { String after; try { Date date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault()).parse(before); after = new SimpleDateFormat("MM-dd HH:mm", Locale.getDefault()).format(date); } catch (ParseException e) { KLog.e("??" + e.toString()); return before; } return after; }
From source file:org.mustard.android.provider.StatusNetJSONUtil.java
public static Notice getNotice(JSONObject json) throws JSONException { Notice notice = new Notice(); notice.setId(json.getLong("id")); notice.setText(json.getString("text")); notice.setTruncated(json.getBoolean("truncated")); try {/* www. j ava 2s. com*/ notice.setCreated_at(df.parse(json.getString("created_at"))); } catch (ParseException e) { if (MustardApplication.DEBUG) Log.e(TAG, e.toString()); } notice.setSource(json.getString("source")); notice.setIn_reply_to_screen_name(json.getString("in_reply_to_screen_name")); try { notice.setIn_reply_to_user_id(json.getLong("in_reply_to_user_id")); notice.setIn_reply_to_status_id(json.getLong("in_reply_to_status_id")); } catch (JSONException e) { } ArrayList<Attachment> attachments = new ArrayList<Attachment>(); try { JSONArray jattachments = json.getJSONArray("attachments"); if (jattachments != null) { for (int i = 0; i < jattachments.length(); i++) { JSONObject enclosure = jattachments.getJSONObject(i); Attachment a = new Attachment(); a.setMimeType(enclosure.getString("mimetype")); a.setSize(enclosure.getLong("size")); a.setUrl(enclosure.getString("url")); attachments.add(a); //if (MustardApplication.DEBUG) Log.d(TAG,"Found attachment: " + a.getUrl()); } notice.setAttachments(attachments); } } catch (JSONException e) { } if (json.has("geo")) { try { JSONObject geo = json.getJSONObject("geo"); JSONArray coordinates = null; if (geo.has("coordinates")) { try { coordinates = geo.getJSONArray("coordinates"); notice.setGeo(true); notice.setLat(coordinates.getDouble(0)); notice.setLon(coordinates.getDouble(1)); } catch (JSONException e) { e.printStackTrace(); notice.setGeo(false); } } else { Log.d(TAG, "Geo tag empty"); notice.setGeo(false); } } catch (JSONException e) { notice.setGeo(false); } } else { Log.d(TAG, "No geo tag"); notice.setGeo(false); } notice.setFavorited(json.getBoolean("favorited")); return notice; }
From source file:org.mumod.android.provider.StatusNetJSONUtil.java
public static Group getGroup(JSONObject json) throws JSONException { Group group = new Group(); try {//from w ww . j ava 2 s. co m group.setId(json.getLong("id")); group.setUrl(json.getString("url")); group.setNickname(json.getString("nickname")); group.setFullname(json.getString("fullname")); // group.setHomepage_url(json.getString("homepage_url")); group.setOriginal_logo(json.getString("original_logo")); group.setHomepage_logo(json.getString("homepage_logo")); group.setStream_logo(json.getString("stream_logo")); group.setMini_logo(json.getString("mini_logo")); group.setHomepage(json.getString("homepage")); group.setDescription(json.getString("description")); group.setLocation(json.getString("location")); try { group.setCreated(df.parse(json.getString("created"))); } catch (ParseException e) { if (MustardApplication.DEBUG) Log.e(TAG, e.toString()); } try { group.setModified(df.parse(json.getString("modified"))); } catch (ParseException e) { if (MustardApplication.DEBUG) Log.e(TAG, e.toString()); } } catch (Exception e) { throw new JSONException(e.getMessage()); } return group; }
From source file:org.mumod.android.provider.StatusNetJSONUtil.java
public static Notice getNoticeFromSearch(JSONObject json) throws JSONException { Notice notice = new Notice(); notice.setId(json.getLong("id")); notice.setText(json.getString("text")); try {//from ww w . j av a 2 s.c o m notice.setCreated_at(dfs.parse(json.getString("created_at"))); } catch (ParseException e) { if (MustardApplication.DEBUG) Log.e(TAG, "Parsing created_at: " + e.toString()); } notice.setSource(json.getString("source")); try { notice.setIn_reply_to_screen_name(json.getString("to_user")); } catch (JSONException e) { if (MustardApplication.DEBUG) Log.e(TAG, e.toString()); } try { notice.setIn_reply_to_user_id(json.getLong("to_user_id")); } catch (JSONException e) { if (MustardApplication.DEBUG) Log.e(TAG, e.toString()); } return notice; }
From source file:de.tudarmstadt.dvs.myhealthassistant.myhealthhub.services.InternalSensorService.java
private static double convertTimeToDouble(String fullTime, String dateFormat, String applyPattern) { SimpleDateFormat fullDate = new SimpleDateFormat(dateFormat); SimpleDateFormat timeDate = new SimpleDateFormat(applyPattern); try {// w w w.ja va2 s.c o m Date now = fullDate.parse(fullTime); String strDate = timeDate.format(now); double parseDate = Double.parseDouble(strDate); if (parseDate >= 24.00d) return parseDate - 24; return parseDate; } catch (ParseException e) { Log.e(TAG, e.toString()); e.printStackTrace(); } return Double.parseDouble("00.00"); }