[CoffeeScript] How do I handle time zones and date/time formatting in CoffeeScript?

Handling time zones and date/time formatting in CoffeeScript can be done using JavaScript's Date object and various libraries. Here's an example of how you can handle time zones and date/time formatting in CoffeeScript:

  1. Get the current date and time in a specific time zone:
1# Import the moment-timezone library
2moment = require("moment-timezone")
3
4# Set the desired time zone
5timeZone = "America/New_York"
6
7# Get the current date and time in the specified time zone
8currentTime = moment().tz(timeZone)
  1. Format the date and time:
1# Use the format() method to format the date and time
2formattedDateTime = currentTime.format("YYYY-MM-DD HH:mm:ss")
3
4# Output the formatted date and time
5console.log(formattedDateTime)
  1. Convert a date and time from one time zone to another:
1# Convert a date and time from one time zone to another
2convertedTime = currentTime.clone().tz("Asia/Tokyo")
3
4# Output the converted date and time
5console.log(convertedTime.format("YYYY-MM-DD HH:mm:ss"))

Note that the above example uses the moment-timezone library, which provides extensive support for time zone manipulation and formatting. You can install it using npm:

1npm install moment-timezone

Feel free to adjust the time zone and date/time format patterns according to your requirements.