MarioLuisGarcia

Somebody: 听说你会 python, 你能把今天的日期打印出来吗?

  •  
  •   MarioLuisGarcia · Jul 25, 2014 · 5202 views
    This topic created in 4485 days ago, the information mentioned may be changed or developed.
    You: Ahha, it's easy, look!

    print '2014-07-25'

    Somebody: 这我也会啊。

    You: 你是要复杂点的不?

    Somebody: 嗯咯。

    You: 好,看这个:

    import time
    import datetime
    print str(datetime.datetime.fromtimestamp(time.mktime(time.strptime('2014-07-25','%Y-%m-%d'))))[:10]

    Somebody: 那要是你不知道今天是几号呢?

    You: 我可以用这种方法

    import datetime
    print str(datetime.datetime.today())[:10]

    Somebody: 一百天前的日期你也能知道吗?

    You: 当然啊

    from datetime import datetime, timedelta
    today = datetime.today()
    a_hundred_days_ago = today - timedelta(days = 100)
    print str(a_hundred_days_ago)[:10]

    Somebody: 靠,那假设你没有python呢

    You: 你微微一笑,掏出了[ 此处填入软文推广设备名称 ] , 哈哈, 我有它呀!

    --------------------------------------------------------------------------------------------------------------------------------

    @All rights reserverd
    10 replies  •  2014-07-26 23:20:33 +08:00
    Livid
    Livid
    MOD
    PRO
    Jul 25, 2014❤️2
    1
    lightening
    lightening
    Jul 25, 2014
    2
    RoR 用户表示:

    100.days.ago
    lizheming
    lizheming
    Jul 25, 2014
    3
    @Livid Arrow能把时间戳语义化(类似 1天前 这种),但是好像不能将语义化的时间转换成时间戳。请问有没有这种相关的库呢?
    wuma
    wuma
    Jul 25, 2014
    4
    不错
    est
    est
    Jul 25, 2014
    5
    @lightening 打印上周星期三是几号。
    nine
    nine
    Jul 26, 2014
    6
    ruby 表示毫无压力

    require 'active_support/core_ext'

    p Date.today
    p Date.yesterday
    p Date.tomorrow

    p Date.today + 10.days + 8.hours + 15.minute + 59.second

    p Time.now.to_date


    @est
    require 'active_support/core_ext'

    p Date.today.day - Date.today.wday - 4
    ffffwh
    ffffwh
    Jul 26, 2014
    7
    这是在说“我的库很好”的意思么?
    yangqi
    yangqi
    Jul 26, 2014
    8
    <?php

    echo date("Y-m-d");

    echo date("d");

    echo date("Y-m-d", strtotime("100 days ago"));
    Todd_Leo
    Todd_Leo
    Jul 26, 2014 via iPhone
    9
    bash> date +%Y-%m-%d
    > date --date="100 days ago" +%Y-%m-%d
    limon
    limon
    Jul 26, 2014
    10
    python其实挺啰嗦的。。。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   5481 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 56ms · UTC 02:02 · PVG 10:02 · LAX 18:02 · JFK 21:02
    ♥ Do have faith in what you're doing.