如何根据营业时间确定企业是否营业(Swift

编程入门 行业动态 更新时间:2024-10-26 02:33:44
本文介绍了如何根据营业时间确定企业是否营业(Swift-iOS)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个正在 Swift 中构建的应用程序,需要确定商店/餐厅当前是否营业.它查询我可以控制的数据库,因此我可以随意设置开放时间.目前,我将一周中的每一天的 openTime/closeTime 列设置为时间戳.例如:MonOpen = 11:00,MonClose = 19:00.

I have an app that I'm building in Swift that needs to determine if a store/restaurant is currently open. It queries a database that I have control of, so I can set the open hours however I'd like. Currently I have an openTime/closeTime column for each day of the week set as a timestamp. For example: MonOpen = 11:00, MonClose = 19:00.

我如何使用 swift 确定营业地点当前是否营业?我想像 if currentTime > 之类的东西MonOpen &当前时间

How can I use swift to determine if the place of business is currently open? I'm imagining something like if currentTime > MonOpen & currentTime < MonClose {...

iOS Starbucks 应用就是一个例子.如果您前往地点,则每个地点都会列出营业至 22:00"或营业至 23:00".

An example of this is the iOS Starbucks app. If you go to locations, each location is listed with an "Open until 22:00" or "Open until 23:00."

推荐答案

这只是玩弄时区的问题,无论您是使用用户系统的时区还是让他们在应用设置中选择另一个时区:

It's just a matter of playing with the timezone, whether you use the user system's timezone or let them choose another one in the app's settings:

let tz = NSTimeZone.defaultTimeZone() let now = NSCalendar.currentCalendar()ponentsInTimeZone(tz, fromDate: NSDate()) if now.weekDay == 2 && now.hour > MonOpen && now.hour < MonClose { // The store is open }

更多推荐

如何根据营业时间确定企业是否营业(Swift

本文发布于:2023-11-26 22:07:58,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1635393.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:营业时间   企业   Swift

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!