123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- package com.sysmodel;
- import java.sql.Timestamp;
- import java.util.ArrayList;
- import java.util.Calendar;
- import java.util.Date;
- import java.util.List;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- public class Util{
- private static Pattern pattern = Pattern.compile("^(-|\\+)?\\d+(\\.\\d+)?$");
- /**
- * format yyyy-MM-dd HH:mm:ss 格式事件
- *
- * @return String
- */
- public static String getDateTime() {
- return getDateTime("yyyy-MM-dd HH:mm:ss");
- }
- /**
- * yyyy-MM-dd 格式日期
- *
- * @return String
- */
- public static String getDate() {
- return getDateTime("yyyy-MM-dd HH:mm:ss").substring(0, 10);
- }
- public static String getDateTime(String timeFormat) {
- Calendar calendar = Calendar.getInstance();
- java.text.SimpleDateFormat df = new java.text.SimpleDateFormat(timeFormat);
- return df.format(calendar.getTime());
- }
- public static String getDateTime(String timeFormat, Timestamp timestamp) {
- if (timestamp == null)
- return "";
- if (timeFormat == null)
- return timestamp.toString();
- if (timeFormat.equals(""))
- return timestamp.toString();
- java.text.SimpleDateFormat df = new java.text.SimpleDateFormat(timeFormat);
- return df.format(new Date(timestamp.getTime()));
- }
- public static Timestamp getTimestampDateTime() {
- String sysTime = getDateTime("yyyy-MM-dd HH:mm:ss");
- Timestamp timestamp = Timestamp.valueOf(sysTime);
- return timestamp;
- }
- /**
- * @param sqlCondition
- * format a,b,c
- * @return 'a','b','c'
- */
- public static String convertSqlIN(String sqlCondition) {
- if (sqlCondition == null)
- return "";
- if (sqlCondition.equals(""))
- return "";
- String[] temp = sqlCondition.split(",");
- StringBuffer sb = new StringBuffer();
- for (int i = 0; i < temp.length; i++) {
- if (i == 0)
- sb.append('\'' + temp[i] + '\'');
- else
- sb.append(",'" + temp[i] + '\'');
- }
- return sb.toString();
- }
- /**
- * @param sqlCondition
- * format a,b,c
- * @return 'a','b','c'
- */
- public static String convertSqlIN(String[] str) {
- if (str == null)
- return "";
- if (str.length == 0)
- return "";
- StringBuffer sb = new StringBuffer();
- for (int i = 0; i < str.length; i++) {
- if (i == 0)
- sb.append('\'' + str[i] + '\'');
- else
- sb.append(",'" + str[i] + '\'');
- }
- return sb.toString();
- }
- public static String convertString(String[] str, String separator) {
- if (str == null)
- return "";
- if (str.length == 0)
- return "";
- StringBuffer sb = new StringBuffer();
- for (int i = 0; i < str.length; i++) {
- if (i == 0)
- sb.append(str[i]);
- else
- sb.append(separator).append(str[i]);
- }
- return sb.toString();
- }
- public static void main(String[] asd) {
- }
- public static boolean isNumeric(String str) {
- Matcher isNum = pattern.matcher(str);
- if (!isNum.matches()) {
- return false;
- }
- return true;
- }
- /**
- * @param str
- * 字符串
- * @param separator
- * 分隔符
- * @return 字符串的List
- */
- public static List<String> convertString(String str, String separator) {
- List<String> list = new ArrayList<String>(3);
- String[] subValue = str.split(separator);
- for (int i = 0; i < subValue.length; i++) {
- list.add(subValue[i]);
- }
- return list;
- }
- }
|