MarioLuisGarcia

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

  •  
  •   MarioLuisGarcia · Jul 25, 2014 · 4778 views
    This topic created in 4312 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
        1
    Livid  
    MOD
    PRO
       Jul 25, 2014   ❤️ 2
    lightening
        2
    lightening  
       Jul 25, 2014
    RoR 用户表示:

    100.days.ago
    lizheming
        3
    lizheming  
       Jul 25, 2014
    @Livid Arrow能把时间戳语义化(类似 1天前 这种),但是好像不能将语义化的时间转换成时间戳。请问有没有这种相关的库呢?
    wuma
        4
    wuma  
       Jul 25, 2014
    不错
    est
        5
    est  
       Jul 25, 2014
    @lightening 打印上周星期三是几号。
    nine
        6
    nine  
       Jul 26, 2014
    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
        7
    ffffwh  
       Jul 26, 2014
    这是在说“我的库很好”的意思么?
    yangqi
        8
    yangqi  
       Jul 26, 2014
    <?php

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

    echo date("d");

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