在JSP页面只获取时分秒的问题

作为一个小白,今天遇到了这样一个问题,在数据库中的一个表里有一个营业时间的字段,在数据库中是Date类型,会默认的把年月日都存进去,在服务器端取出来的也就是一个带日期的营业时间,明显不是我想要的,在网上找了一阵,发现没有想要的答案,于是果断将数据库中的营业时间在服务器端取出后,直接按照date的类型传给了页面,这个时候遇到了一个新的问题,页面上是一个时间插件来显示,所以,不能直接放进去,所以在JS代码中将需要的数据取出,然后再通过 document.getElementById("openTime").value=oT;这个将值放进插件中,具体代码如下:

//这里是显示的是营业时间,为time类型
                                        <input id="openTime" type="time" value="" />
	    				<span>到</span>
	    				<input id="closeTime"type="time" value="" />
	    				<span>24小时制</span>
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAyMAAABiCAYAAABDPwyRAAARTElEQVR4Ae3df2xV5R3H8U+1rYaWjEjKxppI/+n+oCywJRLSZsAfQiL8ISSzf+CMzIjTQSLO1WU0BkisizbDkk2zrJ2imUTrfrAl8w/qHzoDKTNBTAom9p+Cti69K2mzFUtrYDltH3ju4dx77m3vveee87ybkHPO8zzn+fF6+jycb++9bcXM1NR18YUAAggggAACCCCAAAIIlFjgthK3R3MIIIAAAggggAACCCCAwKwAwQjfCAgggAACCCCAAAIIIBCJAMFIJOw0igACCCCAAAIIIIAAAgQjfA8ggAACCCCAAAIIIIBAJAIEI5Gw0ygCCCCAAAIIIIAAAggQjPA9gAACCCCAAAIIIIAAApEIVJai1UvDw6VohjYQQAABBBBAAAEEEEAgRgIV/J2RGM0WXUUAAQQQQAABBBBAIEECvE0rQZPJUBBAAAEEEEAAAQQQiJMAwUicZou+IoAAAggggAACCCCQIAGCkQRNJkNBAAEEEEAAAQQQQCBOAgQjcZot+ooAAggggAACCCCAQIIECEYSNJkMBQEEEEAAAQQQQACBOAkQjMRptugrAggggAACCCCAAAIJEiAYSdBkMhQEEEAAAQQQQAABBOIkQDASp9mirwgggAACCCCAAAIIJEiAYCRBk8lQEEAAAQQQQAABBBCIkwDBSJxmi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AIIIBClAMFIlPq0jQACCCCAAAIIIICAwwIEIw5PPkNHAAEEEEAAAQQQQCBKAYKRKPVpGwEEEEAAAQQQQAABhwUIRhyefIaOAAIIIIAAAggggECUAgQjUerTNgIIIIAAAggggAACDgsQjDg8+QwdAQQQQAABBBBAAIEoBQhGotSnbQQQQAABBBBAAAEEHBYgGHF48hk6AggggAACCCCAAAJRChCMRKlP2wgggAACCCCAAAIIOCxAMOLw5DN0BBBAAAEEEEAAAQSiFCAYiVKfthFAAAEEEEAAAQQQcFiAYMThyWfoCCCAAAIIIIAAAghEKUAwEqU+bSOAAAIIIIAAAggg4LAAwYjDk8/QEUAAAQQQQAABBBCIUoBgJEp92kYAAQQQQAABBBBAwGEBghGHJ5+hI4AAAggggAACCCAQpQDBSJT6tI0AAggggAACCCCAgMMCBCMOTz5DRwABBBBAAAEEEEAgSgGCkSj1aRsBBBBAAAEEEEAAAYcFCEYcnnyGjgACCCCAAAIIIIBAlAIEI1Hq0zYCCCCAAAIIIIAAAg4LEIw4PPkMHQEEEEAAAQQQQACBKAUIRqLUp20EEEAAAQQQQAABBBwWqCzF2C8ND5eiGdpAAAEEEEAAAQQQQACBGAlUzExNXY9Rf+kqAggggAACCCCAAAIIJESAt2klZCIZBgIIIIAAAggggAACcRMgGInbjNFfBBBAAAEEEEAAAQQSIkAwkpCJZBgIIIAAAggggAACCMRNgGAkbjNGfxFAAAEEEEAAAQQQSIgAwUhCJpJhIIAAAggggAACCCAQNwGCkbjNGP1FAAEEEEAAAQQQQCAhAgQjCZlIhoEAAggggAACCCCAQNwECEbiNmP0FwEEEEAAAQQQQACBhAj8H5WWOcrvV4i9AAAAAElFTkSuQmCC" alt="" />
<pre name="code" class="javascript">
效果大概就是这样,这里面的时间要有一个默认值,这个值是写在value里面的,但是由于服务器端传来的是一个date类型数据,所以这个时候就用JS实现了一下转换,具体代码如下

 
<pre name="code" class="javascript">                        var oh = ${openTime.getHours()};
   	        	var om = ${openTime.getMinutes()};
	        	var ch = ${closeTime.getHours()};
	        	var cm = ${closeTime.getMinutes()};
	        	var oT= setTime(oh,om); 
	        	 document.getElementById("openTime").value=oT;
	        	 var cT= setTime(ch,cm);	        	 
	        	 document.getElementById("closeTime").value=cT;
  function  setTime(h,m){
        var option = "";
        if(h<10){
        option +="0"+h;
        }else{
        option += h;
        }
        if(m<10){
        option +=":0"+m;
        }else{
        option += ":"+m;
        }
        return option;
       
       }
 
将时间拼好之后,直接放进value中,就会直接在页面中显示出来了。
有什么不对的地方,希望大家帮忙指出,谢谢大家。

  • 0
    点赞
  • 0
    评论
  • 0
    收藏
  • 打赏
    打赏
  • 扫一扫,分享海报

©️2022 CSDN 皮肤主题:大白 设计师:CSDN官方博客 返回首页

打赏作者

Cter12138

你的鼓励将是我创作的最大动力

¥2 ¥4 ¥6 ¥10 ¥20
输入1-500的整数
余额支付 (余额:-- )
扫码支付
扫码支付:¥2
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值