Python datetime.time 模块,strftime() 实例源码

我们从Python开源项目中,提取了以下17个代码示例,用于说明如何使用datetime.time.strftime()

项目:kritzbot-legacy    作者:kritzware    | 项目源码 | 文件源码
def local_time(self):
        localtime = timezone(str(TIME_ZONE))
        time = datetime.now(localtime)
        format_time = time.strftime('%H:%M:%S')
        if TIME_ZONE == 'US/Eastern':
            output = "Local time: {} EST".format(format_time)
        if TIME_ZONE == 'Europe/London':
            output = "Local time: {} GMT".format(format_time)
        if TIME_ZONE == 'Europe/Oslo':
            output = "Local time: {} CEST".format(format_time)
        return output
项目:kritzbot-legacy    作者:kritzware    | 项目源码 | 文件源码
def local_time(self):
        from modules.bot import bot_msg
        localtime = timezone(str(TIME_ZONE))
        time = datetime.now(localtime)
        format_time = time.strftime('%H:%M:%S')
        if TIME_ZONE == 'US/Eastern':
            output = "Local time: {} EST".format(format_time)
        if TIME_ZONE == 'Europe/London':
            output = "Local time: {} GMT".format(format_time)
        if TIME_ZONE == 'Europe/Oslo':
            output = "Local time: {} CEST".format(format_time)
        bot_msg(output)
项目:pysport    作者:sportorg    | 项目源码 | 文件源码
def set_time(self, time):
        """Set si station internal time.
        @param time: time as a python datetime object.
        """
        bintime = (SIReader._to_str(int(time.strftime('%y')), 1)
                   + SIReader._to_str(time.month, 1)
                   + SIReader._to_str(time.day, 1)
                   + SIReader._to_str(((time.isoweekday() % 7) << 1) + time.hour // 12, 1)
                   + SIReader._to_str((time.hour % 12) * 3600 + time.minute * 60 + time.second, 2)
                   + SIReader._to_str(int(round(time.microsecond / 1000000.0 * 256)), 1)
                   )

        self._send_command(SIReader.C_SET_TIME, bintime)
        self.beep()
项目:pokelector    作者:Kostronor    | 项目源码 | 文件源码
def weekdayStr(date):
    return date.strftime("%A")


# Returns the weekday as a string in its abbreviated form
项目:pokelector    作者:Kostronor    | 项目源码 | 文件源码
def weekdayStrAbv(date):
    return date.strftime("%a")


# Returns the day of the month
项目:pokelector    作者:Kostronor    | 项目源码 | 文件源码
def monthStr(date):
    return date.strftime("%B")


# Returns the month as a string in its abbreviated form
项目:pokelector    作者:Kostronor    | 项目源码 | 文件源码
def monthStrAbv(date):
    return date.strftime("%b")


# Returns the quarter in the year
项目:pokelector    作者:Kostronor    | 项目源码 | 文件源码
def year(date):
    return date.strftime("%Y")


# Returns the year and month as a concatenated string
项目:pokelector    作者:Kostronor    | 项目源码 | 文件源码
def time_label_12(min_num):
    hours, minutes = divmod(min_num, 60)
    timestamp = time(hour=hours, minute=minutes)
    return time.strftime(timestamp, '%I:%M %p')

# Given a minute number, return the 24-hour time label
项目:pokelector    作者:Kostronor    | 项目源码 | 文件源码
def time_label_24(min_num):
    hours, minutes = divmod(min_num, 60)
    timestamp = time(hour=hours, minute=minutes)
    return time.strftime(timestamp, '%H:%M')

# Given a minute number, return the 15 minute interval it occures in
项目:pokelector    作者:Kostronor    | 项目源码 | 文件源码
def label_hh(min_num):
    hours, minutes = divmod(min_num, 60)
    timestamp = time(hour=hours, minute=minutes)
    return time.strftime(timestamp, '%I %p')

# Given a minute number, return the 24-hour time label with just hours
项目:pokelector    作者:Kostronor    | 项目源码 | 文件源码
def label_hh24(min_num):
    hours, minutes = divmod(min_num, 60)
    timestamp = time(hour=hours, minute=minutes)
    return time.strftime(timestamp, '%H')

# Given a minute number, return the 15 minute interval label for a 24-hour clock
项目:pokelector    作者:Kostronor    | 项目源码 | 文件源码
def label_15_min_24(min_num):
    interval_num = time_interval_15_min(min_num)
    int_min_num = interval_num * 15
    hours, minutes = divmod(int_min_num, 60)
    timestamp = time(hour=hours, minute=minutes)
    return time.strftime(timestamp, '%H:%M')

# Given a minute number, return the 30 minute interval label for a 24-hour clock
项目:pokelector    作者:Kostronor    | 项目源码 | 文件源码
def label_60_min_24(min_num):
    interval_num = time_interval_60_min(min_num)
    int_min_num = interval_num * 60
    hours, minutes = divmod(int_min_num, 60)
    timestamp = time(hour=hours, minute=minutes)
    return time.strftime(timestamp, '%H:%M')

# Given a minute number, return the 15 minute interval label for a 12-hour clock
项目:pokelector    作者:Kostronor    | 项目源码 | 文件源码
def label_15_min_12(min_num):
    interval_num = time_interval_15_min(min_num)
    int_min_num = interval_num * 15
    hours, minutes = divmod(int_min_num, 60)
    timestamp = time(hour=hours, minute=minutes)
    return time.strftime(timestamp, '%I:%M %p')

# Given a minute number, return the 30 minute interval label for a 12-hour clock
项目:pokelector    作者:Kostronor    | 项目源码 | 文件源码
def label_30_min_12(min_num):
    interval_num = time_interval_30_min(min_num)
    int_min_num = interval_num * 30
    hours, minutes = divmod(int_min_num, 60)
    timestamp = time(hour=hours, minute=minutes)
    return time.strftime(timestamp, '%I:%M %p')

# Given a miute number, return the 60 minute interval label for a 12-hour clock
项目:pokelector    作者:Kostronor    | 项目源码 | 文件源码
def label_60_min_12(min_num):
    interval_num = time_interval_60_min(min_num)
    int_min_num = interval_num * 60
    hours, minutes = divmod(int_min_num, 60)
    timestamp = time(hour=hours, minute=minutes)
    return time.strftime(timestamp, '%I:%M %p')