smoothretro82

working date & time display for Tw.2s4.me

Nov 10th, 2025 (edited)
56
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 KB | None | 0 0
  1. // Assume the necessary environment functions and variables are defined:
  2. // function writeChar(char, length) { ... }
  3. // let w = { tp: function(x, y) { ... } };
  4. // let text = { length: 0 };
  5.  
  6. // Helper function to ensure single-digit numbers have a leading zero (e.g., 09)
  7. function formatTwoDigits(n) {
  8. return n < 10 ? '0' + n : n;
  9. }
  10.  
  11. // Helper function to write an entire string using writeChar
  12. function writeString(str, x, y) {
  13. w.tp(x, y);
  14. for (let i = 0; i < str.length; i++) {
  15. writeChar(str[i], 1);
  16. }
  17. // Simple cleanup for this specific string display area
  18. for (let i = 0; i < (45 - str.length); i++) {
  19. writeChar(" ", 1);
  20. }
  21. }
  22.  
  23.  
  24. function updateTimeDisplay() {
  25. const now = new Date();
  26.  
  27. const currentSeconds = now.getSeconds();
  28. const currentMinutes = now.getMinutes();
  29. const currentHours24 = now.getHours();
  30.  
  31. // --- Format and Display Digital Time (Y=10) ---
  32. const xPos = 1;
  33. const ampm = currentHours24 >= 12 ? 'PM' : 'AM';
  34. const displayHours = currentHours24 % 12 || 12;
  35. const timeString = `${displayHours}:${formatTwoDigits(currentMinutes)}:${formatTwoDigits(currentSeconds)} ${ampm}`;
  36. // Coordinates changed to start display higher up (Y=10)
  37. writeString(timeString, xPos, 10);
  38.  
  39. // --- Format and Display Date (Y=11) ---
  40. // Example date format: Monday, November 10, 2025
  41. // We use toLocaleDateString for easy formatting if available in the environment
  42. const dateString = now.toLocaleDateString(undefined, {
  43. weekday: 'long',
  44. year: 'numeric',
  45. month: 'long',
  46. day: 'numeric'
  47. });
  48. writeString(dateString, xPos, 11);
  49.  
  50.  
  51. // --- Format and Display Timezone (Y=12) ---
  52. // Example timezone format: EST or America/New_York
  53. const timeZoneString = now.toLocaleTimeString(undefined, {
  54. timeZoneName: 'short'
  55. }).split(' ').pop(); // Extracts just the abbreviation (e.g., "EST")
  56.  
  57. writeString(`Timezone: ${timeZoneString}`, xPos, 12);
  58. }
  59.  
  60. // Update everything every 1 second
  61. setInterval(updateTimeDisplay, 1000);
  62.  
Advertisement
Comments
Add Comment
Please, Sign In to add comment