d3.js学习笔记(1)——日期对象和字符串的相互转换

本文介绍d3.js v4版本中如何将日期字符串转换为日期对象,以及如何将日期对象转换回字符串。同时,探讨了日期对象直接运算的结果,并详细列举了d3中的日期格式化选项。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

d3 v4版本
1.将日期字符串转化为d3中的日期对象

    //字符串例如“2018-05-09T20:46:20.040Z”
     var dateParse = d3.timeParse("%Y-%m-%dT%H:%M:%S.%LZ");
     var timeobj=dateParse(timestring);

2.将日期对象转化为字符串形式

     var dateFormat =d3.timeFormat("%b-%Y");
     var timestr=dateFormat(timeobject);

3.若将得到的日期对象直接进行运算,将会得到数值。

4.d3中format格式:
%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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值