当前位置: 首页>>代码示例>>Python>>正文


Python JS.getTime方法代码示例

本文整理汇总了Python中__pyjamas__.JS.getTime方法的典型用法代码示例。如果您正苦于以下问题:Python JS.getTime方法的具体用法?Python JS.getTime怎么用?Python JS.getTime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在__pyjamas__.JS的用法示例。


在下文中一共展示了JS.getTime方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: time

# 需要导入模块: from __pyjamas__ import JS [as 别名]
# 或者: from __pyjamas__.JS import getTime [as 别名]
 def time(self):
     """
     **pyjsdl.time.time**
     
     Return current computer time (in ms).
     """
     ctime = JS("new Date()")
     return ctime.getTime()
开发者ID:jggatc,项目名称:pyjsdl,代码行数:10,代码来源:time.py

示例2: localtime

# 需要导入模块: from __pyjamas__ import JS [as 别名]
# 或者: from __pyjamas__.JS import getTime [as 别名]
def localtime(t=None):
    if t is None:
        t = time()
    date = JS("new Date(@{{t}}*1000)")
    dateOffset = date.getTimezoneOffset()
    tm = struct_time()
    tm_year = tm.tm_year = int(date.getFullYear())
    tm_mon = tm.tm_mon = int(date.getMonth()) + 1
    tm_mday = tm.tm_mday = int(date.getDate())
    tm.tm_hour = int(date.getHours())
    tm.tm_min = int(date.getMinutes())
    tm.tm_sec = int(date.getSeconds())
    tm.tm_wday = (int(date.getDay()) + 6) % 7
    tm.tm_isdst = 0 if timezone == 60*date.getTimezoneOffset() else 1
    startOfYear = JS("new Date(@{{tm_year}},0,1)") # local time
    startOfYearOffset = startOfYear.getTimezoneOffset()
    startOfDay = JS("new Date(@{{tm_year}},@{{tm_mon}}-1,@{{tm_mday}})")
    dt = float(startOfDay.getTime() - startOfYear.getTime())/1000
    dt = dt + 60 * (startOfYearOffset - dateOffset)
    tm.tm_yday = 1 + int(dt/86400.0)
    return tm
开发者ID:audreyr,项目名称:pyjs,代码行数:23,代码来源:time.py

示例3: gmtime

# 需要导入模块: from __pyjamas__ import JS [as 别名]
# 或者: from __pyjamas__.JS import getTime [as 别名]
def gmtime(t=None):
    if t is None:
        t = time()
    date = JS("new Date(@{{t}}*1000)")
    tm = struct_time()
    tm_year = tm.tm_year = int(date.getUTCFullYear())
    tm.tm_mon = int(date.getUTCMonth()) + 1
    tm.tm_mday = int(date.getUTCDate())
    tm.tm_hour = int(date.getUTCHours())
    tm.tm_min = int(date.getUTCMinutes())
    tm.tm_sec = int(date.getUTCSeconds())
    tm.tm_wday = (int(date.getUTCDay()) + 6) % 7
    tm.tm_isdst = 0
    startOfYear = JS("new Date('Jan 1 '+ @{{tm_year}} +' GMT+0000')")
    tm.tm_yday = 1 + int((t - startOfYear.getTime()/1000)/86400)
    return tm
开发者ID:audreyr,项目名称:pyjs,代码行数:18,代码来源:time.py

示例4: mktime

# 需要导入模块: from __pyjamas__ import JS [as 别名]
# 或者: from __pyjamas__.JS import getTime [as 别名]
def mktime(t):
    """mktime(tuple) -> floating point number
    Convert a time tuple in local time to seconds since the Epoch."""
    tm_year = t[0]
    tm_mon = t[1] - 1
    tm_mday = t[2]
    tm_hour = t[3]
    tm_min = t[4]
    tm_sec = t[5]
    date = JS("new Date(@{{tm_year}}, @{{tm_mon}}, @{{tm_mday}}, @{{tm_hour}}, @{{tm_min}}, @{{tm_sec}})") # local time
    utc = JS("Date.UTC(@{{tm_year}}, @{{tm_mon}}, @{{tm_mday}}, @{{tm_hour}}, @{{tm_min}}, @{{tm_sec}})")/1000
    ts = date.getTime() / 1000
    if t[8] == 0:
        if ts - utc == timezone:
            return ts
        return ts + _dst
    return ts
开发者ID:audreyr,项目名称:pyjs,代码行数:19,代码来源:time.py

示例5: utcnow

# 需要导入模块: from __pyjamas__ import JS [as 别名]
# 或者: from __pyjamas__.JS import getTime [as 别名]
 def utcnow(self):
     d = JS("""new Date()""")
     return datetime.utcfromtimestamp(int(d.getTime() / 1000.0))
开发者ID:simbha,项目名称:pyjamas,代码行数:5,代码来源:datetime.py

示例6: strftime

# 需要导入模块: from __pyjamas__ import JS [as 别名]
# 或者: from __pyjamas__.JS import getTime [as 别名]
def strftime(fmt, t=None):
    if t is None:
        t = localtime()
    else:
        if not isinstance(t, struct_time) and len(t) != 9:
            raise TypeError("argument must be 9-item sequence, not float")
    tm_year = t[0]
    tm_mon = t[1]
    tm_mday = t[2]
    tm_hour = t[3]
    tm_min = t[4]
    tm_sec = t[5]
    tm_wday = t[6]
    tm_yday = t[7]
    date = JS("new Date(tm_year, tm_mon - 1, tm_mday, tm_hour, tm_min, tm_sec)")
    startOfYear = JS("new Date(tm_year,0,1)")
    firstMonday = 1 - ((startOfYear.getDay() + 6) % 7) + 7
    firstWeek = JS("new Date(tm_year,0,firstMonday)")
    weekNo = date.getTime() - firstWeek.getTime()
    if weekNo < 0:
        weekNo = 0
    else:
        weekNo = 1 + int(weekNo / 604800000)

    def format(c):
        if c == "%":
            return "%"
        elif c == "a":
            raise NotImplementedError("strftime format character '%s'" % c)
        elif c == "A":
            raise NotImplementedError("strftime format character '%s'" % c)
        elif c == "b":
            raise NotImplementedError("strftime format character '%s'" % c)
        elif c == "B":
            raise NotImplementedError("strftime format character '%s'" % c)
        elif c == "c":
            return date.toLocaleString()
        elif c == "d":
            return "%02d" % tm_mday
        elif c == "H":
            return "%02d" % tm_hour
        elif c == "I":
            return "%02d" % (tm_hour % 12)
        elif c == "j":
            return "%03d" % tm_yday
        elif c == "m":
            return "%02d" % tm_mon
        elif c == "M":
            return "%02d" % tm_min
        elif c == "p":  # FIXME: should be locale dependent
            if tm_hour < 12:
                return "AM"
            return "PM"
        elif c == "S":
            return "%02d" % tm_sec
        elif c == "U":
            raise NotImplementedError("strftime format character '%s'" % c)
        elif c == "w":
            return "%d" % ((tm_wday + 1) % 7)
        elif c == "W":
            return "%d" % weekNo
        elif c == "x":
            return "%s" % date.toLocaleDateString()
        elif c == "X":
            return "%s" % date.toLocaleTimeString()
        elif c == "y":
            return "%02d" % (tm_year % 100)
        elif c == "Y":
            return "%04d" % tm_year
        elif c == "Z":
            raise NotImplementedError("strftime format character '%s'" % c)
        return "%" + c

    result = ""
    remainder = fmt
    re_pct = JS("/([^%]*)%(.)(.*)/")
    JS("var a, fmtChar;")
    while remainder:
        JS(
            """
        a = re_pct.exec(remainder);
        if (!a) {
            result += remainder;
            remainder = null;
        } else {
            result += a[1];
            fmtChar = a[2];
            remainder = a[3];
            if (typeof fmtChar != 'undefined') {
                result += format(fmtChar)
            }
        }
        """
        )
    return result
开发者ID:andreyvit,项目名称:pyjamas,代码行数:97,代码来源:time.py

示例7: strftime

# 需要导入模块: from __pyjamas__ import JS [as 别名]
# 或者: from __pyjamas__.JS import getTime [as 别名]
def strftime(fmt, t=None):
    if t is None:
        t = localtime()
    else:
        if not isinstance(t, struct_time) and len(t) != 9:
            raise TypeError('argument must be 9-item sequence, not float')
    tm_year = t[0]
    tm_mon = t[1]
    tm_mday = t[2]
    tm_hour = t[3]
    tm_min = t[4]
    tm_sec = t[5]
    tm_wday = t[6]
    tm_yday = t[7]
    date = JS("new Date(@{{tm_year}}, @{{tm_mon}} - 1, @{{tm_mday}}, @{{tm_hour}}, @{{tm_min}}, @{{tm_sec}})")
    startOfYear = JS("new Date(@{{tm_year}},0,1)")
    firstMonday = 1 - ((startOfYear.getDay() + 6) % 7) + 7
    firstWeek = JS("new Date(@{{tm_year}},0,@{{firstMonday}})")
    weekNo = date.getTime() - firstWeek.getTime()
    if weekNo < 0:
        weekNo = 0
    else:
        weekNo = 1 + int(weekNo/604800000)

    def format(c):
        if c == '%':
            return '%'
        elif c == 'a':
            return format('A')[:3]
        elif c == 'A':
            return __c__days[format('w')]
        elif c == 'b':
            return format('B')[:3]
        elif c == 'B':
            return __c__months[tm_mon-1]
        elif c == 'c':
            return date.toLocaleString()
        elif c == 'd':
            return "%02d" % tm_mday
        elif c == 'H':
            return "%02d" % tm_hour
        elif c == 'I':
            return "%02d" % (tm_hour % 12)
        elif c == 'j':
            return "%03d" % tm_yday
        elif c == 'm':
            return "%02d" % tm_mon
        elif c == 'M':
            return "%02d" % tm_min
        elif c == 'p': # FIXME: should be locale dependent
            if tm_hour < 12:
                return "AM"
            return "PM"
        elif c == 'S':
            return "%02d" % tm_sec
        elif c == 'U':
            raise NotImplementedError("strftime format character '%s'" % c)
        elif c == 'w':
            return "%d" % ((tm_wday+1) % 7)
        elif c == 'W':
            return "%d" % weekNo
        elif c == 'x':
            return "%s" % date.toLocaleDateString()
        elif c == 'X':
            return "%s" % date.toLocaleTimeString()
        elif c == 'y':
            return "%02d" % (tm_year % 100)
        elif c == 'Y':
            return "%04d" % tm_year
        elif c == 'Z':
            raise NotImplementedError("strftime format character '%s'" % c)
        return "%" + c
    result = ''
    remainder = fmt
    re_pct = JS("/([^%]*)%(.)(.*)/")
    JS("var a, fmtChar;")
    while remainder:
        JS("""
        @{{!a}} = @{{re_pct}}.exec(@{{remainder}});
        if ([email protected]{{!a}}) {
            @{{result}} += @{{remainder}};
            @{{remainder}} = false;
        } else {
            @{{result}} += @{{!a}}[1];
            @{{!fmtChar}} = @{{!a}}[2];
            @{{remainder}} = @{{!a}}[3];
            if (typeof @{{!fmtChar}} != 'undefined') {
                @{{result}} += @{{format}}(@{{!fmtChar}});
            }
        }
        """)
    return str(result)
开发者ID:audreyr,项目名称:pyjs,代码行数:94,代码来源:time.py


注:本文中的__pyjamas__.JS.getTime方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。