ccad57eca7d59d91deb6746092b5975495d8694b.svn-base 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. package com.sysmodel;
  2. import java.sql.Timestamp;
  3. import java.util.ArrayList;
  4. import java.util.Calendar;
  5. import java.util.Date;
  6. import java.util.List;
  7. import java.util.regex.Matcher;
  8. import java.util.regex.Pattern;
  9. public class Util{
  10. private static Pattern pattern = Pattern.compile("^(-|\\+)?\\d+(\\.\\d+)?$");
  11. /**
  12. * format yyyy-MM-dd HH:mm:ss 格式事件
  13. *
  14. * @return String
  15. */
  16. public static String getDateTime() {
  17. return getDateTime("yyyy-MM-dd HH:mm:ss");
  18. }
  19. /**
  20. * yyyy-MM-dd 格式日期
  21. *
  22. * @return String
  23. */
  24. public static String getDate() {
  25. return getDateTime("yyyy-MM-dd HH:mm:ss").substring(0, 10);
  26. }
  27. public static String getDateTime(String timeFormat) {
  28. Calendar calendar = Calendar.getInstance();
  29. java.text.SimpleDateFormat df = new java.text.SimpleDateFormat(timeFormat);
  30. return df.format(calendar.getTime());
  31. }
  32. public static String getDateTime(String timeFormat, Timestamp timestamp) {
  33. if (timestamp == null)
  34. return "";
  35. if (timeFormat == null)
  36. return timestamp.toString();
  37. if (timeFormat.equals(""))
  38. return timestamp.toString();
  39. java.text.SimpleDateFormat df = new java.text.SimpleDateFormat(timeFormat);
  40. return df.format(new Date(timestamp.getTime()));
  41. }
  42. public static Timestamp getTimestampDateTime() {
  43. String sysTime = getDateTime("yyyy-MM-dd HH:mm:ss");
  44. Timestamp timestamp = Timestamp.valueOf(sysTime);
  45. return timestamp;
  46. }
  47. /**
  48. * @param sqlCondition
  49. * format a,b,c
  50. * @return 'a','b','c'
  51. */
  52. public static String convertSqlIN(String sqlCondition) {
  53. if (sqlCondition == null)
  54. return "";
  55. if (sqlCondition.equals(""))
  56. return "";
  57. String[] temp = sqlCondition.split(",");
  58. StringBuffer sb = new StringBuffer();
  59. for (int i = 0; i < temp.length; i++) {
  60. if (i == 0)
  61. sb.append('\'' + temp[i] + '\'');
  62. else
  63. sb.append(",'" + temp[i] + '\'');
  64. }
  65. return sb.toString();
  66. }
  67. /**
  68. * @param sqlCondition
  69. * format a,b,c
  70. * @return 'a','b','c'
  71. */
  72. public static String convertSqlIN(String[] str) {
  73. if (str == null)
  74. return "";
  75. if (str.length == 0)
  76. return "";
  77. StringBuffer sb = new StringBuffer();
  78. for (int i = 0; i < str.length; i++) {
  79. if (i == 0)
  80. sb.append('\'' + str[i] + '\'');
  81. else
  82. sb.append(",'" + str[i] + '\'');
  83. }
  84. return sb.toString();
  85. }
  86. public static String convertString(String[] str, String separator) {
  87. if (str == null)
  88. return "";
  89. if (str.length == 0)
  90. return "";
  91. StringBuffer sb = new StringBuffer();
  92. for (int i = 0; i < str.length; i++) {
  93. if (i == 0)
  94. sb.append(str[i]);
  95. else
  96. sb.append(separator).append(str[i]);
  97. }
  98. return sb.toString();
  99. }
  100. public static void main(String[] asd) {
  101. }
  102. public static boolean isNumeric(String str) {
  103. Matcher isNum = pattern.matcher(str);
  104. if (!isNum.matches()) {
  105. return false;
  106. }
  107. return true;
  108. }
  109. /**
  110. * @param str
  111. * 字符串
  112. * @param separator
  113. * 分隔符
  114. * @return 字符串的List
  115. */
  116. public static List<String> convertString(String str, String separator) {
  117. List<String> list = new ArrayList<String>(3);
  118. String[] subValue = str.split(separator);
  119. for (int i = 0; i < subValue.length; i++) {
  120. list.add(subValue[i]);
  121. }
  122. return list;
  123. }
  124. }