zoukankan      html  css  js  c++  java
  • js时间格式化

    如题,ajax请求获得json数据填充HTML页面,遇到了一个时间无法格式化的问题。

    由于是js中,fmt标签引用无效,网上也搜索了很多js时间格式化的函数均无效。

    由于用的是spring MVC 后来想到了注解,搞定方法是在应用的实体类时间字段上使用注解:

    @DateTimeFormat(pattern = "yyyy-MM-dd hh:mm:ss")//注解可以以该格式注入时间
    @JSONField(format = "yyyy-MM-dd hh:mm:ss") //默认通过ajax json解析后转化为的格式
    private Date upTime;// 上架时间',

    那么js页面无需要处理:
    //获得分页得函数
    function getPage(obj,num,info) {
    $.ajax({
    type: "GET",//请求类型
    url: path+"/getCardsPage",//请求的url
    data: {id: obj,index:num,info:info},//请求参数
    dataType: "json",//ajax接口(请求url)返回的数据类型
    async: false , //true异步,false同步
    success: function (data) {//data:返回数据(json对象)
    $("#storyBooksssss").html("");
    var div = "";
    for (var i = 0; i < data.newList.length; i++) {
    div+="<div class="product_storyList_content_left"><img src="+path+"/static/rootWeb/images/"+data.newList[i].titleImg+" alt="点卡列表"/></div>" +
    " <div class="product_storyList_content_right"><ul>"+
    " <li class="product_storyList_content_dash"><a href="#" class="blue_14">"+data.newList[i].gName+"</a></li>"+
    "<li>顾客评分:<img src="+path+"/static/rootWeb/images/star_red.gif><img src="+path+"/static/rootWeb/images/star_red.gif alt='star'/><img src="+path+"/static/rootWeb/images/star_red.gif alt='star'/><img src="+path+"/static/rootWeb/images/star_red.gif alt='star'/><img src="+path+"/static/rootWeb/images/star_red.gif alt='star'/></li>"+
    "<li>好评率:" + data.newList[i].praiseRate + "%</li>"+
    "<li>点卡名称:" + data.newList[i].cName + "</li>"+
    " <li>上架时间:" + data.newList[i].upTime + "</li>"+
    "<li>" + data.newList[i].cInfo + "</li>"+
    "<li><dl class="product_content_dd"> <dd>&nbsp;&nbsp;</dd>" +
    "<dd><a href="+path+"/static/toCardView/"+ data.newList[i].cId + "/"+data.newList[i].gid+">"+
    "<img src="+path+"/static/rootWeb/images/product_buy_01.gif></a></dd>"+
    " <dd class="footer_dull_red"><span>实际售价:¥"+data.newList[i].price+"</span></dd>"+
    "<dd class="product_content_delete"><span>原价:¥"+data.newList[i].iniPrice+"</span></dd>"+
    "</dl> </li> </ul> </div><div class="product_storyList_content_bottom"></div>";
    }
    div+="<input type='hidden' id='totalPageCount' value="+data.totalPageCount+">";

    $("#storyBooksssss").html(div);
    $("#pageNo").html("");
    $(".page-bar").remove();//错误点,必须加上这句清空
    var page="<div class='page-bar'>"+
    "<p class='page-num-ul'>"+
    "<span>&nbsp;&nbsp;共"+data.totalCount+"条记录</span>"+
    "<span>&nbsp;&nbsp;"+data.currPageNo+"/"+data.totalPageCount+"页</span>";
    if(data.currPageNo>1){
    page+="<a href="javascript:;" id='1' class='first' >&nbsp;&nbsp;首页</a>"+
    "<a href="javascript:;" class='pre' id='"+(data.currPageNo-1)+"'>&nbsp;&nbsp;上一页</a>";
    }
    if(data.currPageNo < data.totalPageCount ){
    page+="<a href="javascript:;" class='next' id='"+(data.currPageNo+1)+"'>&nbsp;&nbsp;下一页</a>"+
    "<a href="javascript:;" class='last' id='"+data.totalPageCount+"'>&nbsp;&nbsp;最后一页</a>";
    }
    page+="<span class='page-go-form'><label>&nbsp;&nbsp;跳转至</label>"+
    "<input type='text' name='inputPage' id='inputPage' class='page-key' />页"+
    "<button type='button' class='page-btn' id='page-btn'>GO</button>"+
    "</span></p></div>";
    $("#pageNo").html(page);
    },
    error: function (data) {//当访问时候,404,500 等非200的错误状态码
    alert("加载分页信息失败!");
    }
    });
    }
    效果:


     
  • 相关阅读:
    senlin __init__() got an unexpected keyword argument 'additional_headers'
    Delphi 全局画点TCanvas.Pixels[X,Y]
    sql server 列修改null 变成not null
    Delphi记录record中的变体
    delphi无边框可拖动窗体
    bootstrap相关资料
    重装windows导致grub损坏
    RabbitMQ的安装(Docker安装)
    RabbitMQ的安装以及使用(Windows环境)
    如果安装rabittmq后,输入http://localhost:15672不出页面的
  • 原文地址:https://www.cnblogs.com/zeussbook/p/8965549.html
Copyright © 2011-2022 走看看