mvan231

Display API start and end date in widget example

Jan 14th, 2022
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. /*
  2. Hello everyone,
  3.  
  4. I‘m currently having an understanding issue with time stamp formatting, and was hoping one of you could help me.
  5.  
  6. The situation is as follows: I’m receiving a json file with a start and an end time in the ‘yyyy-mm-ddThh:mm:ss.SSSZ
  7. */
  8. const date = "2022-01-14T04:45:33.333-0400"
  9.  
  10. let d = new Date()
  11. log(d)
  12.  
  13. let dF = new DateFormatter()
  14. dF.dateFormat = 'yyyy-MM-dd hh:mm:ss.SSSZ'
  15. let dStr = dF.string(d)
  16. log(dF.date(dStr))
  17.  
  18. let data = [{"startTime":"2022-01-14T04:45:33.333-0500","endTime":"2022-01-14T14:45:33.333-0500"}]
  19. let list = new ListWidget()
  20. //const startTime = new Date();
  21. let startTime = data[0].startTime.replace('T', ' ')
  22. log(startTime)
  23. startTime = dF.date(startTime)
  24. let endTime = data[0].endTime.replace('T', ' ')
  25. log(endTime)
  26. endTime = dF.date(endTime)
  27.  
  28. dF.dateFormat = "h:mm"
  29. let textOut = `${dF.string(startTime)} - ${dF.string(endTime)}`
  30. log(textOut)
  31. list.addText(textOut)
  32.  
  33. const line1 = list.addDate(startTime)
  34. line1.applyTimeStyle()
  35.  
  36. Script.setWidget(list)
  37. Script.complete()
  38. list.presentMedium()
Advertisement
Add Comment
Please, Sign In to add comment