首页 \ 问答 \ javascript - 如何从sql server数据库创建日期和时间的倒计时?(javascript - how to create countdown to date and time from sql server database?)

javascript - 如何从sql server数据库创建日期和时间的倒计时?(javascript - how to create countdown to date and time from sql server database?)

这是我第一次在javascript中使用倒计时,所以我对这个主题进行了一些研究,我发现了一些有趣的链接:“ 如何倒计时到日期 ”和“ https://www.sitepoint.com/build-javascript-countdown -timer-no-dependencies / “,但我的问题是,如果我想从数据库中获取数据和时间,我该怎么做? 例如:我有一个带有ID,Event,StartDate,StartTime和EndTime的表事件。 我怎样才能改变:“var end = new Date('02 / 19/2012 10:1 AM');” 从第一个链接或这个:“自动安排时钟”从第二个到倒计时时间,直到具有最近时间和日期的事件,依此类推。 请记住,我是一个非常棒的人,所以请耐心等待。 对不起任何拼写错误。 谢谢!

更新:

这是控制器部分: [HttpGet] public JsonResult GetEvent(int Id) { BOL1.IMS2Entities db = new BOL1.IMS2Entities(); var ev = from e in db.tbl_Event where e.ID == Id select e; //return Json(ev.FirstOrDefault(), JsonRequestBehavior.AllowGet); return Json(Id, JsonRequestBehavior.AllowGet); } [HttpGet] public JsonResult GetEvent(int Id) { BOL1.IMS2Entities db = new BOL1.IMS2Entities(); var ev = from e in db.tbl_Event where e.ID == Id select e; //return Json(ev.FirstOrDefault(), JsonRequestBehavior.AllowGet); return Json(Id, JsonRequestBehavior.AllowGet); }
这是脚本部分:

<script>
    function GetEvent() {
        debugger;
        $.ajax({
            type: "GET",
            url: "Home/GetEvent",
            data: { Id: ID },
            contentType: "application/json;charset=utf-8",
            dataType: "json",
            success: function (result) {
                debugger;
                alert(result)
            },
            error: function (response) {
                debugger;
                alert('error');
            }
        });
    }

    var tbl_Event.StartDate = 'yyyy-MM-dd hh:hh:hh';
    //var ServerDate_Time = '2017-02-17 10:45:00';
    //console.log(CompareDateTime(ServerDate_Time));
    console.log(CompareDateTime(tbl_Event.StartDate + tbl_Event.StartTime))

    //function CompareDateTime (ServerDateTime){
    function CompareDateTime (tbl_Event.StartDate + tbl_Event.StartTime){
        var dateString = new Date();
        var currentTime = new Date(parseInt(dateString));
        var month = ('0' + (currentTime.getMonth() + 1)).slice(-2)
        var day = ('0' + (currentTime.getDate())).slice(-2)
        var year = currentTime.getFullYear();
        var hours = ('0' + (currentTime.getHours())).slice(-2)
        var min = ('0' + (currentTime.getMinutes())).slice(-2)
        var sec = ('0' + (currentTime.getSeconds())).slice(-2)
        var date = year + "-" + month + "-" + day + " " + hours + ":" + min + ":" + sec;

        if(ServerDateTime == date){
            return true;
        }else {
            return false;
        }

    }
    }
</script>


It's my first time using a countdown in javascript so I have researched a little about this topic and I found some interesting links: "how to countdown to a date" and "https://www.sitepoint.com/build-javascript-countdown-timer-no-dependencies/", but my question is if I want to get data and time from the database, how can I do that? E.g.: I have a table Event with ID,Event,StartDate,StartTime and EndTime. How can I change from this: "var end = new Date('02/19/2012 10:1 AM');" from the first link or this: "Schedule the Clock Automatically" from the second to countdown time until event with the most recent time and date, and so on. Please keep in mind that I'm a total nooby so please bear with me. Sorry for any misspelling. Thank you!

Update:

This is the controller part: [HttpGet] public JsonResult GetEvent(int Id) { BOL1.IMS2Entities db = new BOL1.IMS2Entities(); var ev = from e in db.tbl_Event where e.ID == Id select e; //return Json(ev.FirstOrDefault(), JsonRequestBehavior.AllowGet); return Json(Id, JsonRequestBehavior.AllowGet); }
and this is the scripting part:

<script>
    function GetEvent() {
        debugger;
        $.ajax({
            type: "GET",
            url: "Home/GetEvent",
            data: { Id: ID },
            contentType: "application/json;charset=utf-8",
            dataType: "json",
            success: function (result) {
                debugger;
                alert(result)
            },
            error: function (response) {
                debugger;
                alert('error');
            }
        });
    }

    var tbl_Event.StartDate = 'yyyy-MM-dd hh:hh:hh';
    //var ServerDate_Time = '2017-02-17 10:45:00';
    //console.log(CompareDateTime(ServerDate_Time));
    console.log(CompareDateTime(tbl_Event.StartDate + tbl_Event.StartTime))

    //function CompareDateTime (ServerDateTime){
    function CompareDateTime (tbl_Event.StartDate + tbl_Event.StartTime){
        var dateString = new Date();
        var currentTime = new Date(parseInt(dateString));
        var month = ('0' + (currentTime.getMonth() + 1)).slice(-2)
        var day = ('0' + (currentTime.getDate())).slice(-2)
        var year = currentTime.getFullYear();
        var hours = ('0' + (currentTime.getHours())).slice(-2)
        var min = ('0' + (currentTime.getMinutes())).slice(-2)
        var sec = ('0' + (currentTime.getSeconds())).slice(-2)
        var date = year + "-" + month + "-" + day + " " + hours + ":" + min + ":" + sec;

        if(ServerDateTime == date){
            return true;
        }else {
            return false;
        }

    }
    }
</script>


原文:https://stackoverflow.com/questions/42292950
更新时间:2022-03-11 11:03

最满意答案

pathlib模块支持/用于连接路径对象。

>>> p = Path('/etc')
>>> q = p / 'init.d' / 'reboot'
>>> q
PosixPath('/etc/init.d/reboot')
>>> q.resolve()
PosixPath('/etc/rc.d/init.d/halt')

作为如何使用__div__ ,这是一个扩展str的简单类。 它应该工作只要至少一个参数是MyPath一个实例(即,它不适用于两个普通字符串)。

class MyPath(str):
    def __div__(self, other):
        assert isinstance(other, str)
        return os.path.join(self, other)
    def __rdiv__(self, other):
        assert isinstance(other, str)
        return os.path.join(other, self)

# Using __div__
print MyPath("/home/bob") / MyPath("bin")
print MyPath("/home/bob") / "bin"

# Using __rdiv__
print "/home/bob" / MyPath("bin")

The pathlib module supports / for concatenating path objects.

>>> p = Path('/etc')
>>> q = p / 'init.d' / 'reboot'
>>> q
PosixPath('/etc/init.d/reboot')
>>> q.resolve()
PosixPath('/etc/rc.d/init.d/halt')

As an example of how to use __div__, here's a simple class that extends str. It should work as long as at least one argument is an instance of MyPath (i.e., it won't work with two plain strings).

class MyPath(str):
    def __div__(self, other):
        assert isinstance(other, str)
        return os.path.join(self, other)
    def __rdiv__(self, other):
        assert isinstance(other, str)
        return os.path.join(other, self)

# Using __div__
print MyPath("/home/bob") / MyPath("bin")
print MyPath("/home/bob") / "bin"

# Using __rdiv__
print "/home/bob" / MyPath("bin")

相关问答

更多
  • 表达式(sum(row) for row in M)创建了所谓的生成器 。 该生成器将为M每一行评估表达式( sum(row) )一次。 然而,发电机还没有做任何事情,我们只是设置了它。 next(G)的语句next(G)实际上在M上运行生成器。 所以,如果你运行next(G)一次,你会得到第一行的总和。 如果再次运行它,则会得到第二行的总和,以此类推。 >>> M = [[1,2,3], ... [4,5,6], ... [7,8,9]] >>> >>> G = (sum(row) ...
  • 是的你可以。 在模块math有一些特殊的功能编码,如Gamma功能。 看看这里 Yes, you can. In the module math there are special functions coded such as the Gamma function. Look at here
  • 当你这样做 from SomeModule import * 你确实凌驾于内置和函数。 这会将numpy命名空间中的所有内容导入默认命名空间。 您可能想要做的是: import numpy as np 然后,您可以将numpy点函数作为np.dot访问。 通过这种方式,如果它们定义了相同名称的函数,则可以使命名空间不会相互踩踏。 另一个选择,如果你只想要点功能就是这样做: from numpy import dot 然后点函数是numpy中唯一可用的函数。 这些是使用其他模块时采用的两种主要方法。 导 ...
  • 正如您所说的那样,您没有在参数中使用它们(在调用函数时会出现这种情况),您在创建函数时出现的参数中使用它们。 *和**运算符在每种情况下都有不同的用途。 在定义函数时,它们指定位置参数将放在元组中,并且关键字参数将放在dict中。 是的我只是说了一些论点,但在这种情况下它们适用于参数。 def example(*args, **kwargs): print "args: {0}".format(args) print "kwargs: {0}".format(kwargs) example ...
  • 这是适用于计算的科学符号。 E-05意味着10的权力-5: 8.73194...E-05 = 8.73194 * 10^(-5) = 0.000 087 319 4... That's scientific notation applied to computing. E-05 means 10 to the power of -5: 8.73194...E-05 = 8.73194 * 10^(-5) = 0.000 087 319 4...
  • 只有当所有的元素都是特鲁蒂 。 Truthy!= True 。 基本上检查bool(something)是否为True (对于迭代中的所有something )。 >>> "?" == True False >>> "?" == False # it's not False either False >>> bool("?") True only when all the elements are Truthy. Truthy != True. all essentially checks whether ...
  • 如果您使用python3.5,最好的方法是使用typing.Union >>> from typing import Union >>> import numpy as np >>> def fun(data: Union[np.ndarray, list]): pass 如果你一直使用Union [t1,t2,...],你也可以使用typing.TypeVar。 (另外,您可以比代码中的许多联盟更容易地添加和删除TypeVar中的类型) >>> from typing import Ty ...
  • 它是函数的“成员变量”,因此每次调用它时(除非用seed调用时),序列将选择它停止的位置。 It is a "member variable" of the function, so that each time it is called (except when called with something for seed) the sequence will pick of where it left off.

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。