JavaはOracleデータベースの中のDate日付型を読みますが、秒後の0はどうやって切りますか?
3861 ワード
共有方法:なぜ1つの0が多くなりましたか?データベースの中のデータは0がなくて、取り出す時1つの0が多くなりました。これはOracleデータが作った鬼です。解決コードは以下の通りです。
参考になる
DateFormat sdf=new SimpleDateFormat("yyy/MM/dd hh:mm:ss") //書式を定義する
String startDate=sdf.format(user.get Startmate(); //必要なデータをフォーマットに変換して、正しいフォーマットのデータに変換します。
String endDate=sdf.format(user.get Endate);
map.put(「startudte」、startDate); //mapでフォーマットを変えたデータを入れて、putに入れます。
map.put(「endudete」、endDate); //mapの中にはキーが入っています。putを使うと、データが入れ替わります。
listMap.add(map)
参考になる
for (HessianLog hessianLog : hessianLogList) {
Map<String, String> map = new HashMap<String, String>();
map.put("username",hessianLog.getUsername());
map.put("menuname",hessianLog.getMenu_name());
map.put("clientip",hessianLog.getClientip());
if(hessianLog.getIs_error_log()==1){
map.put("is_error_log"," ");
}
else{
map.put("is_error_log"," ");
}
DateFormat sdf = new SimpleDateFormat("yyyy/MM/dd hh:mm:ss");
String rtnType = sdf.format(hessianLog.getDatetimenow());
map.put("datetimenow",rtnType);
map.put("methodname",hessianLog.getMethodname());
map.put("fullclassname",hessianLog.getFullclassname());
map.put("error_message",hessianLog.getError_message());
map.put("menu_id",hessianLog.getMenu_id()+"");
map.put("id",hessianLog.getId()+"");
map.put("userid",hessianLog.getUserid()+"");
map.put("org_id",hessianLog.getOrg_id()+"");
listMap.add(map);
}
//
List<User> list = userService.loadUserByOrgId(ss, ss.getBelongOrgId());
if(list == null) {
return null;
}
List<Map<String,String>> listMap = new ArrayList<Map<String,String>>();
for (User user2 : list) {
if(user2.getUser_type()==0|| user2.getUser_type()==1){
continue;
}
Map<String,String> map = null;
user2.setPassword(null);
try {
// bug,sybase
if(user2.getTelephone()!=null){
user2.setTelephone(user2.getTelephone().trim());
}
map = BeanUtils.describe(user2);
long belong_org = user2.getBelong_org();
int login_level = user2.getLogin_level();
int enabled = user2.getEnabled();
if(enabled == 1){
map.put("enabled_display", " ");
}else if(enabled == 0){
map.put("enabled_display", " ");
}
if(login_level == 0){
map.put("login_level_display", " ");
}else if(login_level == 1){
map.put("login_level_display", " ");
}
Organization org = orgService.loadOrgById(belong_org);
map.put("belong_org_display", org.getName());
} catch (Exception e) {
throw new RuntimeException(e);
}
DateFormat sdf = new SimpleDateFormat("yyyy/MM/dd hh:mm:ss");
String startDate = sdf.format(user2.getStart_date());
String endDate = sdf.format(user2.getEnd_date());
map.put("start_date", startDate);
map.put("end_date", endDate);
listMap.add(map);
}
Map<String,List<Map<String,String>>> resultMap = new HashMap<String,List<Map<String,String>>>();
resultMap.put("data", listMap);
JSONObject jo = JSONObject.fromObject(resultMap);
this.actionWrite(jo.toString());
return null;
}
上记の二つのコードはいずれも一つの原理を使っています。データベースからデータを取り出した后、JSON列と书いてフロントに现れる前に、データ形式を変换します。変換するところは、フォームサイクルのmapの下にあります。時間はユーザ(この例)、または時間は誰の時間ですか?DateFormat sdf=new SimpleDateFormat("yyy/MM/dd hh:mm:ss") //書式を定義する
String startDate=sdf.format(user.get Startmate(); //必要なデータをフォーマットに変換して、正しいフォーマットのデータに変換します。
String endDate=sdf.format(user.get Endate);
map.put(「startudte」、startDate); //mapでフォーマットを変えたデータを入れて、putに入れます。
map.put(「endudete」、endDate); //mapの中にはキーが入っています。putを使うと、データが入れ替わります。
listMap.add(map)