Okay, so I was working on a project today where I needed to display the current time in Fiji. Sounds simple, right? It turned out to be a little more involved than I initially thought, so I figured I’d share my process.
First Attempt: Just Get the Time
My first thought was, “I’ll just grab the current time and somehow adjust it for Fiji.” I’m using JavaScript, so my go-to was the Date object. I started by just getting the current time:
let now = new Date();
*(now);
This, of course, gave me the time in my timezone, not Fiji’s. Big difference!
Finding Fiji’s Timezone
Next, I needed to figure out Fiji’s timezone. I did a quick search and found out that Fiji is in the Pacific/Fiji timezone. Good to know!
Using toLocaleString()
Then I remembered the toLocaleString() method! It can take timezone options. I tried this:
let now = new Date();
let fijiTime = *("en-US", {timeZone: "Pacific/Fiji"});
*(fijiTime);
Boom! This worked like a charm. The output was a nicely formatted string showing the current date and time in Fiji.
Making it Look Nicer (Optional)
The toLocaleString() output was okay, but I wanted a bit more control over the formatting. So I played around with the options. After some tinkering, I settled on this:
let now = new Date();
let options = {
timeZone: "Pacific/Fiji",
year: 'numeric',
month: 'long',
day: 'numeric',
hour: 'numeric',
minute: 'numeric',
second: 'numeric',
hour12: true
let fijiTime = *("en-US", options);
*(fijiTime);
This gave me a more readable format, with the month spelled out, and using 12-hour time with AM/PM. Much better!
Wrapping Up
So, that’s it! It wasn’t rocket science, but it was a good reminder that even seemingly simple tasks can have a few twists and turns. I started with a basic Date object, figured out the correct timezone for Fiji (Pacific/Fiji), and then used toLocaleString() with some custom options to get the current time formatted exactly how I wanted it. I hope this helps someone else out there!