按时区获取 Person 榆树 中的本地时间
我是 elm 新手,我正在尝试创建一个管理面板,根据当地时间和工作时间显示技术支持列表及其可用时间。 支持者名单:
init flags =
( { supportUserList =
[ { supportName = "Maynard Kaminski"
, numberOfClient = 12
, zone = "Europe/Moscow"
, startTime = "9 am"
, endTime = "1 pm"
}
, { supportName = "Belle Willett"
, numberOfClient = 8
, zone = "Canada/Eastern"
, startTime = "2 pm"
, endTime = "6 pm"
}
, { supportName = "Gaylene Hickson"
, numberOfClient = 7
, zone = "Africa/Nairobi"
, startTime = "6 pm"
, endTime = "10 pm"
}
, { supportName = "Cinthia Talbert"
, numberOfClient = 4
, zone = "Asia/Tokyo"
, startTime = "2 pm"
, endTime = "6 pm"
}
, { supportName = "Sydney Crenshaw"
, numberOfClient = 7
, zone = "Pacific/Honolulu"
, startTime = "6 am"
, endTime = "10 am"
}
]
}
, Cmd.none
)
viewSupporter : Supporter -> Html msg
viewSupporter supporter =
li []
[ text supporter.supportName
, text " "
, text " ("
, text (String.fromInt (supporter.numberOfClient))
, text ")"
, text " "
, text supporter.startTime
, text " - "
, text supporter.endTime
, text " ("
, text "local time ?"
, text ")"
]
预期结果 在此处输入图片描述
当前结果 在此处输入图像描述
我试图检查https://guide.elm-lang.org/effects/time.html 和 如何获取 Elm 的当前时间?
但仍然找不到解决方案。 这是我当前的代码位于 Eillie 中。 花了将近9个小时,没有找到解决方案。我如何通过时区值获取一个人的当地时间。谢谢
I am quite new in elm and I am trying to create an admin panel that shows the technical support list and their available time according to their local time and their working hours.
Supporter List:
init flags =
( { supportUserList =
[ { supportName = "Maynard Kaminski"
, numberOfClient = 12
, zone = "Europe/Moscow"
, startTime = "9 am"
, endTime = "1 pm"
}
, { supportName = "Belle Willett"
, numberOfClient = 8
, zone = "Canada/Eastern"
, startTime = "2 pm"
, endTime = "6 pm"
}
, { supportName = "Gaylene Hickson"
, numberOfClient = 7
, zone = "Africa/Nairobi"
, startTime = "6 pm"
, endTime = "10 pm"
}
, { supportName = "Cinthia Talbert"
, numberOfClient = 4
, zone = "Asia/Tokyo"
, startTime = "2 pm"
, endTime = "6 pm"
}
, { supportName = "Sydney Crenshaw"
, numberOfClient = 7
, zone = "Pacific/Honolulu"
, startTime = "6 am"
, endTime = "10 am"
}
]
}
, Cmd.none
)
viewSupporter : Supporter -> Html msg
viewSupporter supporter =
li []
[ text supporter.supportName
, text " "
, text " ("
, text (String.fromInt (supporter.numberOfClient))
, text ")"
, text " "
, text supporter.startTime
, text " - "
, text supporter.endTime
, text " ("
, text "local time ?"
, text ")"
]
Expected Result
enter image description here
Current Result
enter image description here
I was trying to check https://guide.elm-lang.org/effects/time.html and How do I get the current time in Elm?
But still could not find a solution.
Here is my current code is in Eillie.
Spent almost 9 hours and could not find a solution. How could I get a person's local time by their time zone value. Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要将这些
zone
字符串转换为实际的Time.Zone
,这可以使用 justinmimbs 的 时区库。然后,您需要使用
Time.every
之类的方法获取当前时间,并使用Time.Extra.posixToParts
。一些示例代码:
这是在 ellie-app.com 上运行的相同代码。
You'll want to convert those
zone
strings into actualTime.Zone
s, which can be done with justinmimbs' TimeZone library.Then, you'll need to get the current time with something like
Time.every
, and convert it to local parts withTime.Extra.posixToParts
.Some example code:
Here's the same code running on ellie-app.com.