视频播放器仓库

Time.js 810B

123456789101112131415161718192021222324252627282930
  1. import React from 'react';
  2. import styles from './Time.css';
  3. const formatTime = (seconds) => {
  4. const date = new Date(Date.UTC(1970,1,1,0,0,0,0));
  5. seconds = isNaN(seconds) || seconds > 86400
  6. ? 0
  7. : Math.floor(seconds);
  8. date.setSeconds(seconds);
  9. const duration = date.toISOString().substr(11, 8).replace(/^0{1,2}:?0{0,1}/,'');
  10. return duration;
  11. };
  12. export default ({ currentTime, duration, className }) => {
  13. return (
  14. <div className={[
  15. styles.component,
  16. className
  17. ].join(' ')}>
  18. <span className={styles.current}>
  19. { formatTime(currentTime) }
  20. </span>
  21. /
  22. <span className={styles.duration}>
  23. { formatTime(duration) }
  24. </span>
  25. </div>
  26. );
  27. };