如何在Firebase中存储时间值,特别是小时和分钟? [英] How can I store a time value, specifically only hour and minute in Firebase?

查看:59
本文介绍了如何在Firebase中存储时间值,特别是小时和分钟?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不需要将此时间与任何日期相关联.实际上,我不希望它与特定日期相关联.它与一周中的一般日期联系在一起.星期一,星期六等

I don't need this time associated with any date. In fact, I don't want it associated with a specific date. It's more so associated with a generic day of the week. Monday, Saturday, etc.

例如,您当地的咖啡店根据星期一的时间来设置星期一的时间.不是基于2017年5月22日或2017年5月29日等.

For example, your local coffee shop sets their hours for Monday based on the fact that it is a Monday. Not based on it being May 22, 2017 or May 29, 2017, etc.

我可以做类似的事情...

I could do something like...

"Local Coffee Shoppe": 
{
    "availability": 
    {
        "monday":
        {
            "start":
            {
                "hour": 7,
                "minute": 30
            },
            "end":
            {
                "hour": 21,
                "minute": 0
            }
        }
    }
}

这意味着本地咖啡专柜的营业时间为星期一的上午7:30至晚上9:00.

This would mean the Local Coffee Shoppe is open Mondays from 7:30am to 9:00pm.

这是实现这一目标的最佳方法吗?例如,所有时间都将存储在UTC中,而转换发生在客户端.

Is this the best way to achieve this? All times would be stored in UTC for example, with conversion happening client side.

刚意识到这种方法有一个漏洞.它不包括营业时间超过午夜的营业场所.为了解决这个问题,也许每天都只存储开始",然后存储持续时间" ...

Just realized there is a hole in this approach. It doesn't cover establishments that are open past midnight. To combat this, maybe each day just stores "start" and then "duration"...

    "monday":
    {
        "start":
        {
            "hour": 7,
            "minute": 30
        },
        "duration":
        {
            "hour": 13,
            "minute": 30
        }
    }

因此,它在上午7:30之前开放13小时30分钟. IE.晚上9:00.

So it is open for 13 hours and 30 minutes past 7:30am. I.E. 9:00pm.

推荐答案

我建议按照您的建议仅存储时间戳并提取,这将是一个很好的方法,这还将使您已经拥有扩展使用范围的代码如果需要的话.

I would recommend just storing timestamps and extracting as you suggested, that would be a good approach, this would also allow you to already have the code to expand your use case if you want.

这篇关于如何在Firebase中存储时间值,特别是小时和分钟?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆