Jersey返回时间格式为时间戳,如何格式化?


package com.wizincloud.base.adapter;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.ws.rs.WebApplicationException;
import javax.xml.bind.annotation.adapters.XmlAdapter;

public class DateAdapter extends XmlAdapter<String, Date> {


    private static final SimpleDateFormat dateFormat = new SimpleDateFormat(
    "yyyy-MM-dd HH:mm:ss");


    @Override
    public String marshal(Date v) {
        return dateFormat.format(v);
    }


    @Override
    public Date unmarshal(String v) {
        try {
            return dateFormat.parse(v);
        } catch (ParseException e) {
            throw new WebApplicationException();
        }
    }
}

实体类:

import java.util.Date;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
@XmlAccessorType(XmlAccessType.NONE)
public class BaseModel {

 /** * 执行插入操作的时间 */
 @XmlJavaTypeAdapter(DateAdapter.class)
 private Date created_at;

 /** * 执行更新操作的时间 */
 @XmlJavaTypeAdapter(DateAdapter.class)
 private Date updated_at;





 public Date getCreated_at() {
 return created_at;
 }



 public void setCreated_at(Date created_at) {
 this.created_at = created_at;
 }



 public Date getUpdated_at() {
 return updated_at;
 }




 public void setUpdated_at(Date updated_at) {
 this.updated_at = updated_at;
 }

}

你可能感兴趣的:(时间,格式化,jersey)