如何将Calendar转换为JSON

时间:2017-04-05 00:04:48

标签: java angularjs json rest

我正在开发像这样的休息应用程序

@XmlRootElement
@Entity
@Table(name = "tb_verarq")
public class Verificacao implements Serializable{

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    private Long id;
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "ultima_verificacao")      
    private Calendar dataHoraUltimaVerificacao;
}

在XML上会看到:

 <?xml version="1.0" encoding="UTF-8" standalone="yes" ?> 
- <verificacao>
  <dataHoraUltimaVerificacao>2017-04-04T20:57:46.490-03:00</dataHoraUltimaVerificacao> 
  <id>1</id> 
  </verificacao>

但在我的网页上只出现一个数字

enter image description here

更新 这是我的Angular

var professoresModulo = angular.module('arquivocopemModulo',[]);

professoresModulo.controller("arqcopem-controller", function($scope,$http){

    urlVerificacao="http://localhost:8080/monitoriabnb/rest/verificacaocopem";

    $scope.buscaVerificacao  = function (){
        $http.get(urlVerificacao).success(function(verificacao) {
            console.log(verificacao);
            $scope.verificacao = verificacao;
        }).error(function(erro) {
            alert(erro);
        });
    }


    $scope.buscaVerificacao();


});

我试试这个,但不能工作

$scope.verificacao.dataHoraUltimaVerificacao = Date.parse($scope.verificacao.dataHoraUltimaVerificacao);

我尝试使用Angular进行转换但不起作用 对我有什么建议吗?

1 个答案:

答案 0 :(得分:0)

尝试使用有效处理DATE TIME的momentjs。您可以修改以下代码

$scope.verificacao.dataHoraUltimaVerificacao = moment($scope.verificacao.dataHoraUltimaVerificacao, 'YYYY-MM-DD HH:mm').toDate();

您也可以通过使用时刻函数提取日期,月份,年份,小时,分钟等来转换为自定义格式。

var dd = $scope.verificacao.dataHoraUltimaVerificacao.getDate();
var mm = $scope.verificacao.dataHoraUltimaVerificacao.getMonth();
var yy = $scope.verificacao.dataHoraUltimaVerificacao.getUTCFullYear();

return ((dd) + "/" + (mm+1) + "/" + yy);

我希望这有帮助......