1.Date转String
new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()); public String getAppDate() { if (appDate == null) return ""; SimpleDateFormat df = new SimpleDateFormat(StaticConstant.dateFormat);// 设置日期格式 return df.format(appDate); } 2.String转Date new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(onlineEndTime);//String onlineEndTime public void setAppDate(String appDate) { SimpleDateFormat df = new SimpleDateFormat(StaticConstant.dateFormat);// 设置日期格式 Date timestamp = null; try { timestamp = df.parse(appDate); } catch (ParseException e) { e.printStackTrace(); } this.appDate = timestamp; } public static final String dateFormat = "yyyy-MM-dd HH:mm:ss";3.String转Timestamp
方法1:
carousel.setOnlineStartTime(new Timestamp(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"). parse(onlineStartTime).getTime()));
//String onlineStartTime 方法2: SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String time = df.format(new Date()); Timestamp ts = Timestamp.valueOf(time); 4.Timestamp转String SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//定义格式,不显示毫秒 Timestamp now = new Timestamp(System.currentTimeMillis());//获取系统当前时间 String str = df.format(now); public String getOnlineStartTime() { if(onlineStartTime == null) return ""; SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); return sdf.format(onlineStartTime); } //Timestamp onlineStartTime
