Coding
PromptBeginner5 minmarkdown
Nano Banana Pro
Agent skill for nano-banana-pro
7
The HTML `datetime-local` input type is timezone-agnostic - it sends values like "2025-10-01T20:30" without timezone information. This creates a common web development challenge: how does the server know if this time is UTC, user's local time, or something else?
Sign in to like and favorite skills
The HTML
datetime-local input type is timezone-agnostic - it sends values like "2025-10-01T20:30" without timezone information. This creates a common web development challenge: how does the server know if this time is UTC, user's local time, or something else?
"2025-10-01T20:30" (no timezone info)// Detect user's timezone const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone; // Result: "America/New_York", "Europe/London", etc. // Send with form as hidden field <input type="hidden" name="timezone" value={timezone} />
<!-- Only shown when JavaScript is disabled --> <noscript> <select name="timezone"> <option value="UTC">UTC</option> <option value="America/New_York">Eastern Time</option> <option value="Europe/London">London Time</option> <!-- etc... --> </select> </noscript>
// Handle all scenarios if (!timezone || timezone === 'Unknown (JavaScript required)') { // No timezone info: treat as UTC dateObject = new Date(submittedValue + 'Z'); } else if (timezone === 'UTC') { // UTC selected: force UTC parsing dateObject = new Date(submittedValue + 'Z'); } else { // Timezone available: treat as local time dateObject = new Date(submittedValue); }
Hydration-Safe State Management:
const [timezone, setTimezone] = useState('Unknown (JavaScript required)'); useEffect(() => { setTimezone(Intl.DateTimeFormat().resolvedOptions().timeZone); }, []);
UTC to Local Conversion for Input:
// Convert UTC datetime to local for datetime-local input const localTime = new Date(utcDate.getTime() - utcDate.getTimezoneOffset() * 60000); const formatted = localTime.toISOString().slice(0, 16);
Progressive Enhancement Structure:
<!-- Always include timezone field --> <input type="hidden" name="timezone" value={detectedTimezone} /> <!-- Fallback for no JavaScript --> <noscript> <select name="timezone"> <!-- timezone options --> </select> </noscript>
Consistent UTC Storage:
Timezone Handling Logic:
function parseDateTime(dateString, timezone) { if (!timezone || timezone === 'Unknown (JavaScript required)') { return new Date(dateString + 'Z'); // Force UTC } if (timezone === 'UTC') { return new Date(dateString + 'Z'); // Force UTC } return new Date(dateString); // Local time interpretation }
See the demo route in this project at
/ - a complete working implementation
that demonstrates the progressive enhancement pattern with automatic timezone
detection (JavaScript enabled) and manual timezone selection (JavaScript disabled).