[英]Convert a string of (for example) Y-m-d from PHP to the equivalent date format in JS
I have a PHP variable which is a date format string, it is "Ymd" but could be other date format strings, I'd like to pass this to a script which requires a JS date format string.我有一个 PHP 变量,它是一个日期格式字符串,它是“Ymd”,但可能是其他日期格式字符串,我想将它传递给一个需要 JS 日期格式字符串的脚本。
Therefore my Ymd from PHP is the equivalent of YYYY-MM-DD in JS.因此,我来自 PHP 的 Ymd 相当于 JS 中的 YYYY-MM-DD。
What can I do on either the PHP or JS side to convert the PHP based date format string of Ymd to the JS equivalent?我可以在 PHP 或 JS 端做什么来将基于 PHP 的 Ymd 日期格式字符串转换为 JS 等效项?
I am looking to convert the date format string itself, not the actual date.我正在寻找转换日期格式字符串本身,而不是实际日期。
I'm really not sure on what your issue is.我真的不确定你的问题是什么。 But I've spun up a local version of what you're using and I've created the following code:但是我已经创建了您正在使用的本地版本,并且创建了以下代码:
<input value="<?php echo date('Y-m-d'); ?>" id="litepicker">
<script src="https://cdn.jsdelivr.net/npm/litepicker/dist/js/main.js"></script>
<script>
var picker = new Litepicker({
element: document.getElementById('litepicker'),
format: 'D MMM, YYYY',
});
</script>
As you can see, its a new Litepicker instance, formatted to look nicely, but the input element has the value set to what you'd get back from the database, and it looks like this on screen:如您所见,它是一个新的 Litepicker 实例,其格式看起来不错,但输入元素的值设置为您从数据库返回的值,它在屏幕上看起来像这样:
If I'm misunderstanding you, please let me know.如果我误解了你,请告诉我。 But I cannot see the issue.但我看不到这个问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.