diff --git a/src/routes/etf/[tickerID]/options/+page.svelte b/src/routes/etf/[tickerID]/options/+page.svelte index 499734c8..b39e513e 100644 --- a/src/routes/etf/[tickerID]/options/+page.svelte +++ b/src/routes/etf/[tickerID]/options/+page.svelte @@ -47,26 +47,23 @@ const putOpenInterestList = data?.getOptionsPlotData?.putOpenInterestList; -function formatTime(timestamp) { - // Convert timestamp to milliseconds - var date = new Date(timestamp * 1000); +function formatTime(timeString) { + // Split the time string into components + const [hours, minutes, seconds] = timeString.split(':').map(Number); - // hours, minutes, and seconds - var hours = date.getHours(); - var minutes = date.getMinutes(); - var seconds = date.getSeconds(); + // Determine AM or PM + const period = hours >= 12 ? 'PM' : 'AM'; - hours = (hours < 10 ? "0" : "") + hours; - minutes = (minutes < 10 ? "0" : "") + minutes; - seconds = (seconds < 10 ? "0" : "") + seconds; + // Convert hours from 24-hour to 12-hour format + const formattedHours = hours % 12 || 12; // Converts 0 to 12 for midnight - // Format the date string - var formattedDate = hours + ":" + minutes + ":" + seconds - //var formattedDate = hours + ":" + minutes + ":" + seconds; + // Format the time string + const formattedTimeString = `${formattedHours.toString().padStart(2, '0')}:${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')} ${period}`; - return formattedDate; + return formattedTimeString; } + function formatDate(dateStr) { // Parse the input date string (YYYY-mm-dd) var date = new Date(dateStr); @@ -530,7 +527,7 @@ $: { - {item?.time} + {formatTime(item?.time)} diff --git a/src/routes/stocks/[tickerID]/options/+page.svelte b/src/routes/stocks/[tickerID]/options/+page.svelte index ea856958..727cdeba 100644 --- a/src/routes/stocks/[tickerID]/options/+page.svelte +++ b/src/routes/stocks/[tickerID]/options/+page.svelte @@ -68,6 +68,21 @@ function formatDate(dateStr) { return formattedDate; } +function formatTime(timeString) { + // Split the time string into components + const [hours, minutes, seconds] = timeString.split(':').map(Number); + + // Determine AM or PM + const period = hours >= 12 ? 'PM' : 'AM'; + + // Convert hours from 24-hour to 12-hour format + const formattedHours = hours % 12 || 12; // Converts 0 to 12 for midnight + + // Format the time string + const formattedTimeString = `${formattedHours.toString().padStart(2, '0')}:${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')} ${period}`; + + return formattedTimeString; +} function changeStatement(event) { @@ -509,7 +524,7 @@ $: { - {item?.time} + {formatTime(item?.time)}