Advertisement
Guest User

Untitled

a guest
Aug 24th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. import React, { Component } from 'react';
  2. import moment from 'moment';
  3. import math from 'mathjs';
  4.  
  5. class App extends Component {
  6. render() {
  7. //get the current date and time
  8. const right_now = moment();
  9.  
  10. // get a nicely formatted date and time
  11. const formatted_right_now = right_now.format("dddd, MMMM Do YYYY, h:mm:ss a");
  12.  
  13. // add 7 days, 4 hours and 32 minutes to the current time
  14. right_now.add(7, 'days');
  15. right_now.add(4, 'hours');
  16. right_now.add(32, 'minutes');
  17.  
  18. // get a nicely formatted date and time for the new time
  19. const formatted_later = right_now.format("dddd, MMMM Do YYYY, h:mm:ss a");
  20.  
  21. //added math
  22. const f1 = math.fraction(4, 7); // the fraction 4/7
  23. const f2 = math.fraction(3, 8); // the fraction 3/8
  24. const f3 = math.add(f1, f2); // the fraction 53/56
  25. const formatted_fraction = math.format(f3, { fraction: 'ratio' });
  26.  
  27.  
  28. return (
  29. <div className="App">
  30. <h1>Playing with dates</h1>
  31. <h2>The date and time right now is: </h2>
  32. <p>{formatted_right_now}</p>
  33.  
  34. <h2>The date and time 7 days, 4 hours and 32 minutes from now is: </h2>
  35. <p>{formatted_later}</p>
  36.  
  37. <h2>4/7 + 3/8 = </h2>
  38. <p>{formatted_fraction}</p>
  39. </div>
  40.  
  41.  
  42. );
  43. }
  44. }
  45.  
  46. export default App;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement