@@ -195,6 +195,187 @@ const setCurrentDateTime = () => {
195195 minuteProgressText . value = minuteProgress ; //set minute progress text
196196 secondProgressText . value = secondProgress ; //set second progress text
197197} ;
198+ const setCurrentDateTimeUtc = ( ) => {
199+ //function to set current date and time in UTC
200+ const currentYear = currentDateTime . getFullYear ( ) ; //current year
201+ const currentUtcYear = currentDateTime . getUTCFullYear ( ) ; //current year in UTC
202+ const currentMonth = currentDateTime . getMonth ( ) ; //current month
203+ const currentUtcMonth = currentDateTime . getUTCMonth ( ) ; //current month in UTC
204+ const currentDate = currentDateTime . getDate ( ) ; //current date
205+ const currentUtcDate = currentDateTime . getUTCDate ( ) ; //current date in UTC
206+ const currentDay = currentDateTime . getDay ( ) ; //current day of week
207+ const currentUtcDay = currentDateTime . getUTCDay ( ) ; //current day of week in UTC
208+ const currentHour = currentDateTime . getHours ( ) ; //current hour
209+ const currentUtcHour = currentDateTime . getUTCHours ( ) ; //current hour in UTC
210+ const currentMinute = currentDateTime . getMinutes ( ) ; //current minute
211+ const currentUtcMinute = currentDateTime . getUTCMinutes ( ) ; //current minute in UTC
212+ const currentSecond = currentDateTime . getSeconds ( ) ; //current second
213+ const currentUtcSecond = currentDateTime . getUTCSeconds ( ) ; //current second in UTC
214+ const currentMillisecond = currentDateTime . getMilliseconds ( ) ; //current millisecond
215+ const currentUtcMillisecond = currentDateTime . getUTCMilliseconds ( ) ; //current millisecond in UTC
216+ const yearStart = new Date ( currentYear , 0 , 1 ) ; //start of year
217+ const yearEnd = new Date ( currentYear + 1 , 0 , 1 ) ; //end of year
218+ const yearStartUtc = new Date ( currentUtcYear , 0 , 1 ) ; //start of year in UTC
219+ const yearEndUtc = new Date ( currentUtcYear + 1 , 0 , 0 ) ; //end of year in UTC
220+ const monthStart = new Date ( currentYear , currentMonth , 1 ) ; //start of month
221+ const monthEnd = new Date ( currentYear , currentMonth + 1 , 0 ) ; //end of month
222+ const monthStartUtc = new Date ( currentUtcYear , currentUtcMonth , 1 ) ; //start of month in UTC
223+ const monthEndUtc = new Date ( currentUtcYear , currentUtcMonth + 1 , 0 ) ; //end of month in UTC
224+ const weekStart = new Date (
225+ currentYear ,
226+ currentMonth ,
227+ currentDate - currentDay ,
228+ ) ; //start of week
229+ const weekEnd = new Date (
230+ currentYear ,
231+ currentMonth ,
232+ currentDate + ( 7 - currentDay ) ,
233+ ) ; //end of week
234+ const weekStartUtc = new Date (
235+ currentUtcYear ,
236+ currentUtcMonth ,
237+ currentUtcDate - currentUtcDay ,
238+ ) ; //start of week in UTC
239+ const weekEndUtc = new Date (
240+ currentUtcYear ,
241+ currentUtcMonth ,
242+ currentUtcDate + ( 7 - currentUtcDay ) ,
243+ ) ; //end of week in UTC
244+ const dayStart = new Date ( currentYear , currentMonth , currentDate ) ; //start of day
245+ const dayEnd = new Date ( currentYear , currentMonth , currentDate + 1 ) ; //end of day
246+ const dayStartUtc = new Date (
247+ currentUtcYear ,
248+ currentUtcMonth ,
249+ currentUtcDate ,
250+ ) ; //start of day in UTC
251+ const dayEndUtc = new Date (
252+ currentUtcYear ,
253+ currentUtcMonth ,
254+ currentUtcDate + 1 ,
255+ ) ; //end of day in UTC
256+ const hourStart = new Date (
257+ currentYear ,
258+ currentMonth ,
259+ currentDate ,
260+ currentHour ,
261+ ) ; //start of hour
262+ const hourEnd = new Date (
263+ currentYear ,
264+ currentMonth ,
265+ currentDate ,
266+ currentHour + 1 ,
267+ ) ; //end of hour
268+ const hourStartUtc = new Date (
269+ currentUtcYear ,
270+ currentUtcMonth ,
271+ currentUtcDate ,
272+ currentUtcHour ,
273+ ) ; //start of hour in UTC
274+ const hourEndUtc = new Date (
275+ currentUtcYear ,
276+ currentUtcMonth ,
277+ currentUtcDate ,
278+ currentUtcHour + 1 ,
279+ ) ; //end of hour in UTC
280+ const minuteStart = new Date (
281+ currentYear ,
282+ currentMonth ,
283+ currentDate ,
284+ currentHour ,
285+ currentMinute ,
286+ ) ; //start of minute
287+ const minuteEnd = new Date (
288+ currentYear ,
289+ currentMonth ,
290+ currentDate ,
291+ currentHour ,
292+ currentMinute + 1 ,
293+ ) ; //end of minute
294+ const minuteStartUtc = new Date (
295+ currentUtcYear ,
296+ currentUtcMonth ,
297+ currentUtcDate ,
298+ currentUtcHour ,
299+ currentUtcMinute ,
300+ ) ; //start of minute in UTC
301+ const minuteEndUtc = new Date (
302+ currentUtcYear ,
303+ currentUtcMonth ,
304+ currentUtcDate ,
305+ currentUtcHour ,
306+ currentUtcMinute + 1 ,
307+ ) ; //end of minute in UTC
308+ const secondStart = new Date (
309+ currentYear ,
310+ currentMonth ,
311+ currentDate ,
312+ currentHour ,
313+ currentMinute ,
314+ currentSecond ,
315+ ) ; //start of second
316+ const secondEnd = new Date (
317+ currentYear ,
318+ currentMonth ,
319+ currentDate ,
320+ currentHour ,
321+ currentMinute ,
322+ currentSecond + 1 ,
323+ ) ; //end of second
324+ const secondStartUtc = new Date (
325+ currentUtcYear ,
326+ currentUtcMonth ,
327+ currentUtcDate ,
328+ currentUtcHour ,
329+ currentUtcMinute ,
330+ currentUtcSecond ,
331+ ) ; //start of second in UTC
332+ const secondEndUtc = new Date (
333+ currentUtcYear ,
334+ currentUtcMonth ,
335+ currentUtcDate ,
336+ currentUtcHour ,
337+ currentUtcMinute ,
338+ currentUtcSecond + 1 ,
339+ ) ; //end of second in UTC
340+ const yearProgress = ( currentDateTime - yearStart ) / ( yearEnd - yearStart ) ; //year progress
341+ const yearProgressUtc =
342+ ( currentUtcDateTime - yearStartUtc ) / ( yearEndUtc - yearStartUtc ) ; //year progress in UTC
343+ const monthProgress =
344+ ( currentDateTime - monthStart ) / ( monthEnd - monthStart ) ; //month progress
345+ const monthProgressUtc =
346+ ( currentUtcDateTime - monthStartUtc ) / ( monthEndUtc - monthStartUtc ) ; //month progress in UTC
347+ const weekProgress = ( currentDateTime - weekStart ) / ( weekEnd - weekStart ) ; //week progress
348+ const weekProgressUtc =
349+ ( currentUtcDateTime - weekStartUtc ) / ( weekEndUtc - weekStartUtc ) ; //week progress in UTC
350+ const dayProgress = ( currentDateTime - dayStart ) / ( dayEnd - dayStart ) ; //day progress
351+ const dayProgressUtc =
352+ ( currentUtcDateTime - dayStartUtc ) / ( dayEndUtc - dayStartUtc ) ; //day progress in UTC
353+ const hourProgress = ( currentDateTime - hourStart ) / ( hourEnd - hourStart ) ; //hour progress
354+ const hourProgressUtc =
355+ ( currentUtcDateTime - hourStartUtc ) / ( hourEndUtc - hourStartUtc ) ; //hour progress in UTC
356+ const minuteProgress =
357+ ( currentDateTime - minuteStart ) / ( minuteEnd - minuteStart ) ; //minute progress
358+ const minuteProgressUtc =
359+ ( currentUtcDateTime - minuteStartUtc ) / ( minuteEndUtc - minuteStartUtc ) ; //minute progress in UTC
360+ const secondProgress =
361+ ( currentDateTime - secondStart ) / ( secondEnd - secondStart ) ; //second progress
362+ const secondProgressUtc =
363+ ( currentUtcDateTime - secondStartUtc ) / ( secondEndUtc - secondStartUtc ) ; //second progress in UTC
364+ const yearProgressText = document . getElementById ( "yearProgress" ) ; //year progress text
365+ const monthProgressText = document . getElementById ( "monthProgress" ) ; //month progress text
366+ const weekProgressText = document . getElementById ( "weekProgress" ) ; //week progress text
367+ const dayProgressText = document . getElementById ( "dayProgress" ) ; //day progress text
368+ const hourProgressText = document . getElementById ( "hourProgress" ) ; //hour progress text
369+ const minuteProgressText = document . getElementById ( "minuteProgress" ) ; //minute progress text
370+ const secondProgressText = document . getElementById ( "secondProgress" ) ; //second progress text
371+ yearProgressText . value = yearProgressUtc ; //set year progress text
372+ monthProgressText . value = monthProgressUtc ; //set month progress text
373+ weekProgressText . value = weekProgressUtc ; //set week progress text
374+ dayProgressText . value = dayProgressUtc ; //set day progress text
375+ hourProgressText . value = hourProgressUtc ; //set hour progress text
376+ minuteProgressText . value = minuteProgressUtc ; //set minute progress text
377+ secondProgressText . value = secondProgressUtc ; //set second progress text
378+ } ;
198379window . onload = ( ) => {
199380 setCurrentDateTime ( ) ;
200381} ; //set current date and time when page is loaded
0 commit comments