java常用方法2

xiaoxiao2022-08-07  34


某平台价值19860元的编程课程资料免费领取【点我领取】


public static void setSessionAttributes( String[] keys, Object[] values, HttpSession session) { for (int i = 0; i < keys.length; i++) { session.setAttribute(keys[i], values[i]); } } public static void clearSessionAttributes( String[] keys, HttpSession session) { for (int i = 0; i < keys.length; i++) { session.removeAttribute(keys[i]); } } public static String getTime(String dateTime) { String timeString = ""; String[] tmp = dateTime.split(" "); if (null != tmp && tmp.length == 2) { timeString = tmp[1]; try { timeString = formatDateString(timeString, Constants.TIMEFORMAT); } catch (Exception e) { e.printStackTrace(); } } return timeString; } public static void main(String[] arg) throws ParseException { Date date = new Date(); System.out.println(dateToString(date, Constants.DATEFORMAT)); System.out.println( dateToString(getYesterday(date), Constants.DATEFORMAT)); System.out.println(getFormatDateNoTime(date)); String a1 = "1981-01-01"; //String a2 = new Date().toString(); System.out.print(Util.formatStringToDate(a1, "yyyy-MM-dd")); } public static List getContainedList(Object[] objects) { if (null == objects) return null; List list = new ArrayList(); for (int i = 0; i < objects.length; i++) { list.add(objects[i]); } return list; } public static Date getYesterday(Date date) { return new Date(date.getTime() - 24 * 60 * 60 * 1000); } // 传入{1,2,3,4,5,6} 输出 '1','2','3','4','5','6' public static String getListStrings(String[] userids) { String listStr = ""; for (int i = 0; i < userids.length; i++) { if (i == 0) { listStr = "'" + userids[i] + "'"; } else { listStr = listStr + ",'" + userids[i] + "'"; } } return listStr; } //传入{1,2,3,4,5,6} 输出 1,2,3,4,5,6 public static String getProcDeleteString(String[] userids) { String listStr = ""; for (int i = 0; i < userids.length; i++) { if (i == 0) { listStr = userids[i]; } else { listStr = listStr + "," + userids[i]; } } return listStr; } //传入{1,2,3,4,5,6} 输出 1,2,3,4,5,6 public static String getProcDeleteString(long[] userids) { String listStr = ""; for (int i = 0; i < userids.length; i++) { if (i == 0) { listStr = String.valueOf(userids[i]); } else { listStr = listStr + "," + String.valueOf(userids[i]); } } return listStr; } //传入一个list 里面包含着 1,2,3,4,5,6 个元素 输出 1,2,3,4,5,6 public static String getProcDeleteString(List lists) { String listStr = ""; for (int i = 0; i < lists.size(); i++) { if (i == 0) { listStr = (String)lists.get(i); } else { listStr = listStr + "," + (String)lists.get(i); } } return listStr; } public static Date getFormatDate(Date date) { String strdate = Util.dateToString(date, Constants.DATETIMEFORMAT); Date tempdate = Util.stringToDate(strdate, Constants.DATEFORMAT); return tempdate; }
转载请注明原文地址: https://www.6miu.com/read-4973819.html

最新回复(0)