android/java 根据当前时间判断股票交易状态(未开盘 交易中 休市中 已收盘)
1 /** 2 * @param data yyyy-MM-dd HH:mm:ss 时间 3 * @return 未开盘 交易中 休市中 已收盘 4 */ 5 public static String getSotckStatus(String data) { 6 String s = ""; 7 try { 8 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 9 Date date1 = sdf.parse(data); 10 Calendar cal = Calendar.getInstance(); 11 cal.setTime(date1); 12 // Calendar cal = Calendar.getInstance(); 13 int hour = cal.get(Calendar.HOUR_OF_DAY); 14 int minutes = cal.get(Calendar.MINUTE); 15 if (hour >= 0 && hour < 10) { 16 if (hour >= 9) { 17 if (minutes >= 30)// 9:30-10:00 18 s = "交易中"; 19 else 20 // 9:00-9:30 21 s = "未开盘"; 22 } else {// 0:00-9:00 23 s = "未开盘"; 24 } 25 } else if (hour > 9 && hour < 12) { 26 if (hour > 10) { 27 if (hour >= 11) { 28 if (minutes >= 30)// 11:30-12:00 29 s = "休市中"; 30 else 31 // 11:00-11:30 32 s = "交易中"; 33 } else {// 10:00-11:00 34 s = "交易中"; 35 } 36 } else { 37 if (minutes >= 30)// 9:30-10:00 38 s = "交易中"; 39 else 40 // 9:00-9:30 41 s = "未开盘"; 42 } 43 } else if (hour >= 11 && hour < 13) { 44 if (hour < 12) { 45 if (minutes >= 30)// 11:30-12:00 46 s = "休市中"; 47 else 48 // 11:00-11:30 49 s = "交易中"; 50 } else { 51 s = "休市中"; 52 } 53 } else if (hour > 12 && hour < 15) { 54 if (hour >= 13) {// 13:00-15:00 55 s = "交易中"; 56 } else {// 12:00-13:00 57 s = "休市中"; 58 } 59 } else if (hour >= 15 && hour <= 24) {// 15:00-24:00 60 s = "已结束"; 61 } 62 } catch (Exception e) { 63 e.printStackTrace(); 64 return s; 65 } 66 return s; 67 }