D3.js | d3.utcDay() Function

The d3.utcDay() function in D3.js is used to return date in “YYYY-MM-DD” format in Coordinated Universal Time (UTC).

Syntax:

d3.utcDay(Date);

Parameters: This function accepts a parameter “Date”.



Return Value: This function returns the given date in a specific format.

Below programs illustrate the d3.utcDay() function in D3.js:
Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head>
    <script src=
            "https://d3js.org/d3.v4.min.js">
  </script>
</head>
  
<body>
  
    <script>
        // Initialising a current date
        var now = new Date;
  
        // calling d3.utcDay()
        var day = d3.utcDay(now);
  
        // Getting the date
        console.log(day);
    </script>
</body>
  
</html>

chevron_right


Output:

"2019-07-20T00:00:00.000Z"

Example 2: Below code calculates the difference between two given dates.

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head>
    <script src=
            "https://d3js.org/d3.v4.min.js">
  </script>
</head>
  
<body>
  
    <script>
        // Initialising start and end date
        var start = new Date(2015, 02, 01);
        var end = new Date(2015, 02, 04);
  
        // Calling the utcDay() function to
        // calculate the difference between two dates
        var a = d3.utcDay.count(start, end);
  
        // Getting the calculated dates
        console.log(a);
    </script>
</body>
  
</html>

chevron_right


Output:

3


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.