viralraval5

Untitled

Aug 23rd, 2019
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // returns current timestamp
  2. const set_current_timestamp = function() {
  3. returnmoment().format('X');
  4. };
  5.  
  6. // converts timestamp to date
  7. // pass timestamp in function
  8. const getDateFormatFromTimeStamp = function(dt) {
  9. returnmoment.unix(dt).format('MM/DD/YYYY');
  10. };
  11.  
  12. // returns timestamp of start of today
  13. const getCurrentDateDayStartTimestamp = function() {
  14. returnmoment('00:00:00', 'HH:mm:ss').format('X');
  15. };
  16.  
  17. // returns timestamp of end of today
  18. const getCurrentDateDayEndTimestamp = function() {
  19. returnmoment('23:59:59', 'HH:mm:ss').format('X');
  20. };
  21.  
  22. // converts date format to timestamp
  23. // pass date in function Ex: 23-08-2019 10:23:10
  24. const setDateFormatToTimeStamp = function(dt) {
  25. returnmoment(dt, 'DD-MM-YYYY h:mm:ss').unix();
  26. };
  27.  
  28. // converts time to timestamp for today
  29. // pass time in function Ex: "10:25 am"
  30. const getTimestampFromTime = function(time) {
  31. returnmoment(time, 'HH:mm A').format('X');
  32. };
  33.  
  34. // returns start timestamp of current month
  35. const getStartofMonth = () => {
  36. returnmoment()
  37. .startOf('month')
  38. .format('X');
  39. };
  40.  
  41. // returns end timestamp of current month
  42. const getEndofMonth = () => {
  43. returnmoment()
  44. .endOf('month')
  45. .format('X');
  46. };
  47.  
  48. // returns start timestamp of any month of any year
  49. // pass year and month in function Ex: 2019, april
  50. const getMonthStartTimestamp = (year, month) => {
  51. returnmoment()
  52. .year(year)
  53. .month(month)
  54. .date(1)
  55. .hours(0)
  56. .minutes(0)
  57. .seconds(0)
  58. .milliseconds(0)
  59. .format('X');
  60. };
  61.  
  62. // this function returns last of any month of any year
  63. // this will work afor leap year also
  64. // pass month and year in function argument Ex: ('february', 2024)
  65. const getLastDayofMonth = (month, year) => {
  66. returnmoment()
  67. .month(month)
  68. .year(year)
  69. .daysInMonth();
  70. };
  71.  
  72. // returns end timestamp of any month of any year
  73. // to get end of month timestamp, last date of the month is also required
  74. // Whatever the "getLastDateOfMonth" function returns is passed in this function's argument
  75. // pass year and month in function Ex: 2019, april,
  76. const getMonthEndTimestamp = (year, month, lastDay) => {
  77. returnmoment()
  78. .year(year)
  79. .month(month)
  80. .date(lastDay)
  81. .hours(0)
  82. .minutes(0)
  83. .seconds(0)
  84. .milliseconds(0)
  85. .format('X');
  86. };
  87.  
  88. // returns timestamp from time format of any day
  89. // pass timestamp in function
  90. const convertTimestampToTime = timestamp => {
  91. returnmoment(timestamp*1000).format('hh:mm a');
  92. };
  93.  
  94. // returns start timesamp of any day
  95. // pass date in YYYY-MM-DD format to the function Ex: 2019-04-02
  96. const getDateStartTimtstamp = date => {
  97. returnmoment(date)
  98. .startOf('day')
  99. .format('X');
  100. };
  101.  
  102. // returns end timesamp of any day
  103. // pass date in YYYY-MM-DD format to the function Ex: 2019-04-02
  104. const getDateEndTimtstamp = date => {
  105. returnmoment(date)
  106. .endOf('day')
  107. .format('X');
  108. };
Add Comment
Please, Sign In to add comment