2013-08-06 2 views

ответ

12

Дата 1374561814000 В настоящее время Unix Time Stamp.

Вы можете определить, как вы хотите, чтобы дата отображалась в вашем при передаче в вашу диаграмму. Прочитайте руководство d3 по адресу Time formatting, это даст вам лучшее понимание.

chart.xAxis.tickFormat(function(d) { 
    // Will Return the date, as "%m/%d/%Y"(08/06/13) 
    return d3.time.format('%x')(new Date(d)) 
}); 

Или вы можете вернуть штамп даты с указанием даты/месяц/год, для этого можно просто сделать:

return d3.time.format('%d/%m/%y')(new Date(d)) 

Допустим, вы хотите штамп времени Unix вернуть дату с течением времени в miniutes и часы часов было бы просто:

return d3.time.format('%X')(new Date(d)) // Capital X 

Приведенные выше примеры были протестированы HERE, имеют игру вокруг, используя значения ниже (taken from the d3 time formatting docs).

Constructs a new local time formatter using the given specifier. The specifier string may contain the following directives.  

- %a - abbreviated weekday name. 
- %A - full weekday name. 
- %b - abbreviated month name. 
- %B - full month name. 
- %c - date and time, as "%a %b %e %H:%M:%S %Y". 
- %d - zero-padded day of the month as a decimal number [01,31]. 
- %e - space-padded day of the month as a decimal number [ 1,31]; equivalent to %_d. 
- %H - hour (24-hour clock) as a decimal number [00,23]. 
- %I - hour (12-hour clock) as a decimal number [01,12]. 
- %j - day of the year as a decimal number [001,366]. 
- %m - month as a decimal number [01,12]. 
- %M - minute as a decimal number [00,59]. 
- %L - milliseconds as a decimal number [000, 999]. 
- %p - either AM or PM. 
- %S - second as a decimal number [00,61]. 
- %U - week number of the year (Sunday as the first day of the week) as a decimal number [00,53]. 
- %w - weekday as a decimal number [0(Sunday),6]. 
- %W - week number of the year (Monday as the first day of the week) as a decimal number [00,53]. 
- %x - date, as "%m/%d/%Y". 
- %X - time, as "%H:%M:%S". 
- %y - year without century as a decimal number [00,99]. 
- %Y - year with century as a decimal number. 
- %Z - time zone offset, such as "-0700". 
- %% - a literal "%" character. 

Надеюсь, это поможет.

И если другие члены чувствуют, что это нуждается в улучшении, пожалуйста, продолжайте и улучшите ответ.

+0

Я понял. Спасибо за помощь. По оси x дата отображается в формате d/m/y. Но когда я пытаюсь навести курсор на определенную координату, она показывает NaN/NaN/NaN. В чем может быть проблема? – Mausumi

Смежные вопросы