html 将日期和时间推送到隐藏字段

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了html 将日期和时间推送到隐藏字段相关的知识,希望对你有一定的参考价值。

<!--START code current date and time to 2 hidden fields-->
<script>
  $(document).ready(function() {
      var date = function() {
          var dateObject = new Date();
          var disp = [];
          var monthNames = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];

          disp.push(monthNames[dateObject.getMonth()]);
          disp.push(dateObject.getDate());
          disp.push(dateObject.getFullYear());

          return disp.join(' ');
      }; //function

      var time = function() {
          var dateObject = new Date();
          var disp = [];
          disp.push(dateObject.getHours());
          disp.push(dateObject.getMinutes());
          disp.push(dateObject.getSeconds());
          
          return disp.join(':');
      }; //function

      $('input[name="' + base64_encode('date') + '"]').attr("value", date()); //append the date to the field
      $('input[name="' + base64_encode('time') + '"]').attr("value", time()); //append the time to the field

  }); // ready
</script>
<!--END code current date and time to 2 hidden fields-->
<!--START code current date and time to hidden field-->
<!--Zoho requires the format yyyy-mm-dd hh:mm:ss-->
<script>
    $(document).ready(function() {
        var gDate = function() {
            var dateObject = new Date();
            var disp = [];

            disp.push(dateObject.getFullYear());
            disp.push(dateObject.getMonth() + 1);
            disp.push(dateObject.getDate());

            return disp.join('-');
        }; //function

        var gTime = function() {
            var dateObject = new Date();
            var disp = [];
            disp.push(dateObject.getHours());
            disp.push(dateObject.getMinutes());
            disp.push(dateObject.getSeconds());
            
            return disp.join(':');
        }; //function
        
        var datetime = gDate() + ' ' + gTime();
        $( 'input[name="'+ base64_encode( 'datetime' ) +'"]').attr("value", datetime );

    }); // ready

</script>
<!--END code current date and time to hidden field-->
<!--START code current date and time to hidden field-->
<!--Format dd/mm/yyyy dd:mm AM-->
<script>
    $(document).ready(function() {
        var gDate = function() {
            var dateObject = new Date();
            var disp = [];

            disp.push(dateObject.getDate());
            disp.push(dateObject.getMonth() + 1);
            disp.push(dateObject.getFullYear());

            return disp.join('/');
        }; //function

        var gTime = function() {
            var dateObject = new Date();
            var disp = [];
            var hours = dateObject.getHours();
            if (hours != 12) {
                disp.push(hours % 12);
            } else {
                disp.push(12);
            }
            disp.push(dateObject.getMinutes());
            if (hours < 12) {
                return disp.join(':') + ' AM';
            } else {
                return disp.join(':') + ' PM';
            }
        }; //function
        
        var datetime = gDate() + ' ' + gTime();
        $( 'input[name="'+ base64_encode( 'datetime' ) +'"]').attr("value", datetime );

    }); // ready

</script>
<!--END code current date and time to hidden field-->

以上是关于html 将日期和时间推送到隐藏字段的主要内容,如果未能解决你的问题,请参考以下文章

WIX Navigation V2 - 推送到新屏幕时隐藏底部标签栏

将输入字段推送到数组并循环遍历

如何将文本字段中的数据推送到另一个 VC 中的标签

猫鼬:更新字段,将对象推送到数组中[重复]

将 Django 应用程序推送到 Heroku 后,Dynos 字段为空白

在 AngularJS 和 NodeJS 中隐藏 API 密钥并推送到 Git 和 Heroku