Difference between revisions of "Python: Print waktu"

From OnnoWiki
Jump to navigation Jump to search
 
(One intermediate revision by the same user not shown)
Line 19: Line 19:
 
  n = datetime.datetime.now()
 
  n = datetime.datetime.now()
 
  unix_time = time.mktime(n.timetuple())
 
  unix_time = time.mktime(n.timetuple())
 +
 +
 +
==Ambil Menit dan Detik Saja==
 +
 +
now=datetime.datetime.now()
 +
string_i_want=('%02d:%02d.%d'%(now.minute,now.second,now.microsecond))[:-4]
 +
 +
now=datetime.now()
 +
string_i_want=('%d.%d'%(now.minute*60+now.second,now.microsecond))[:-4]

Latest revision as of 08:56, 30 November 2015

Time

Source

import datetime
print datetime.datetime.now()


Jika dijalankan akan keluar kira-kira

2015-11-28 09:12:03.465258


Time Stamp

import time
import datetime
n = datetime.datetime.now()
unix_time = time.mktime(n.timetuple())


Ambil Menit dan Detik Saja

now=datetime.datetime.now()
string_i_want=('%02d:%02d.%d'%(now.minute,now.second,now.microsecond))[:-4]
now=datetime.now()
string_i_want=('%d.%d'%(now.minute*60+now.second,now.microsecond))[:-4]