简体   繁体   English

html字符串转js脚本

[英]html string to js script

i'm new to HTML and JavaScript but i have to change a string which represents a date in this format: DD/MM/YYYY HH:MM:SS to this format: DD/MM/YYYY HH:MM.我是 HTML 和 JavaScript 的新手,但我必须将表示此格式日期的字符串:DD/MM/YYYY HH:MM:SS 更改为这种格式:DD/MM/YYYY HH:MM。 I am trying to get the value of {{msr.start}} inside of my javascript function so that i can use the slice() function to make it 3 characters shorter, can anyone please tell me how i can get the value of {{msr.start}} inside of my script?我试图在我的 javascript 函数中获取 {{msr.start}} 的值,以便我可以使用 slice() 函数将其缩短 3 个字符,谁能告诉我如何获得 { {msr.start}} 在我的脚本里面? Thanks in advance :)提前致谢 :)

<td colspan="4" class="text-center text-middle" id="abc123">
  {{msr.start}} <--- this contains the right date and time
  <script>
    var tmp = {{msr.start}}.splice(0, 3) <--- here is where i want to use the date and time
    document.getElementById('abc123').innerHTML = tmp
  </script>

You can use let tmp = "{{msr.start}}" and then use substring() Example:您可以使用let tmp = "{{msr.start}}"然后使用substring()示例:

 let tmp = "DD/MM/YYYY HH:MM:SS" //You would use "{{msr.start}}" console.log(tmp.substring(0, tmp.length - 3));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM