简体   繁体   English

将(例如)Ymd 字符串从 PHP 转换为 JS 中的等效日期格式

[英]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.

相关问题 使用JavaScript将Javascript日期对象转换为php Ymd字符串 - Convert Javascript date object to php Y-m-d string using javascript 从Ymd H:i:s格式创建JS Date类 - Create JS Date class from format Y-m-d H:i:s 显示日期 (<!--?php echo date('Y-m-d');?--> ;) 单击按钮时输入 - JQuery JS PHP - Display date (<?php echo date('Y-m-d');?>;) to input when button is click - JQuery JS PHP 从文本创建对象日期,格式为Ymd H:i:s - Create object Date from text in format Y-m-d H:i:s 如何从JS中的Ymd日期获取Unix时间戳? - How to get unix timestamp from Y-m-d date in JS? 搜索验证后,日期格式设置为dd / mm / YY,返回Ymd - Date format set to dd/mm/YY returning Y-m-d after search validation 如何在 Javascript 中将 Epoch 中的日期转换为“Ymd H:i:s”? - How can I convert a date in Epoch to "Y-m-d H:i:s" in Javascript? 获取日期为“ 2015-08-04” {“ YMD”}格式。 如何将指定的日期格式更改为UTC格式? - Getting date in '2015-08-04'{“Y-M-D”} format. How to change the specified date format into UTC format? 带日期的前缀文章关键字(Ymd) - Prefix article keyword with date(Y-m-d) 如何将Rails%d /%m /%Y日期格式字符串转换为dd / mm / yyyy? - How to convert Rails %d/%m/%Y date format string to dd/mm/yyyy?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM