suchen

Heim  >  Fragen und Antworten  >  Hauptteil

python - 如何把152753这个字符串转变成时间格式15:27:53

如何来转换呢?
请各位帮帮我

迷茫迷茫2785 Tage vor555

Antworte allen(4)Ich werde antworten

  • PHP中文网

    PHP中文网2017-04-18 10:28:50

    from datetime import datetime
    s = '152753'
    t = datetime.strptime(s, '%H%M%S').time()
    
    print(t)
    15:27:53

    Antwort
    0
  • PHP中文网

    PHP中文网2017-04-18 10:28:50

    s=str(152753)
    print s[0:2]+':'+s[2:4]+':'+s[4:6]

    Antwort
    0
  • ringa_lee

    ringa_lee2017-04-18 10:28:50

     >>> time = "152753"
     >>> ':'.join(time[i:i+2] for i in range(0, len(time), 2))
     >>> '15:27:53'

    Antwort
    0
  • 大家讲道理

    大家讲道理2017-04-18 10:28:50

    var time = '152753'
    time = time.substring(0,2)+':'+time.substring(2,4)+':'+time.substring(4,6)

    Antwort
    0
  • StornierenAntwort