简体   繁体   English

d3.js时间格式%b%e返回null

[英]d3.js time format %b %e return null

I have read https://github.com/mbostock/d3/wiki/Time-Formatting and related stackoverflow posts, but cannot find answer. 我已经阅读了https://github.com/mbostock/d3/wiki/Time-Formatting和相关的stackoverflow帖子,但是找不到答案。

I already have date in this format. 我已经有这种格式的日期。

Mon Jan 26 2015 00:00:00 GMT-0800 (PST)

But I want to convert them from "%Y-%m-%d" to "%b %e". 但我想将它们从“%Y-%m-%d”转换为“%b%e”。 I directly used 我直接用过

var parse = d3.time.format("%b %e").parse and it returns null. var parse = d3.time.format("%b %e").parse ,它返回null。 I found an old post says because input is not in correct format. 我发现有一条旧帖子说,因为输入的格式不正确。

I also tried "2015-01-26" as input, still return null. 我也尝试将“ 2015-01-26”作为输入,但仍返回null。 So how can I get format as "%b %e" from Mon Jan 26 2015 00:00:00 GMT-0800 (PST)? 那么,如何从Mon Jan 26 2015 00:00:00 GMT-0800 (PST)获得格式为“%b%e”的格式?

You have Mon Jan 26 2015 00:00:00 GMT-0800 (PST) as a string and want to convert it to a date object? 您将Mon Jan 26 2015 00:00:00 GMT-0800(PST)作为字符串并将其转换为日期对象吗?

var someDate = new Date("Mon Jan 26 2015 00:00:00 GMT-0800 (PST)");

Or you have Mon Jan 26 2015 00:00:00 GMT-0800 (PST) as a date object and want to format as a string like %b %e? 或者您将Mon Jan 26 2015 00:00:00 GMT-0800(PST)用作日期对象,并希望将其格式化为%b%e之类的字符串?

var format = d3.time.format("%b %e");
format(someDate);

Or you have Mon Jan 26 2015 00:00:00 GMT-0800 (PST) as a string and you want it as a string like %b %e? 或者您将Mon Jan 26 2015 00:00:00 GMT-0800(PST)作为字符串,并且希望将其作为字符串,如%b%e?

var someDate = new Date("Mon Jan 26 2015 00:00:00 GMT-0800 (PST)");
var format = d3.time.format("%b %e");
format(someDate);

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

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