Python 136

2

Python 136

Saya yakin seseorang dapat melakukan ini dengan lebih baik - Saya belum pernah menggunakan Tkinter sebelumnya. Secara khusus saya bertaruh l.pack()dan l["text"]bisa dihindari.

tk

Golf

from Tkinter import*
from datetime import datetime as d
r=Tk()
l=Label(r)
l.pack()
while 1:
    l["text"]=d(2013,12,25)-d.now()
    r.update()
chmullig
sumber

Jawaban:

1

R

Ini adalah solusi untuk R yang menggunakan GTK + melalui paket gWidgets. Ini adalah kode yang jelek karena saya tidak terbiasa dengan paket gWidgets / GTK + sama sekali.

Kode

Ini kodenya:

library(gWidgets)
options(guiToolkit="RGtk2")

# FUNCTION compute the hours minutes and seconds from time in seconds
fnHMS = function(timeInSec) {
  hours = timeInSec %/% 3600
  minutes = (timeInSec %% 3600) %/% 60
  seconds = (timeInSec %% 3600) %% 60
  return(list(hours = hours, minutes = minutes, seconds = seconds))
}

# test the function
fnHMS(1478843)

# container for the label and the button widget
christmasCountdownContainer = gwindow('Christmas Countdown!!', visible = TRUE)
christmasCountdownGroup = ggroup(horizontal = FALSE,
                                 container = christmasCountdownContainer)
ccWidget1 = glabel(sprintf('%4.0f hours, %4.0f minutes, %4.0f seconds till Christmas!!', 
                           (liHMS <- fnHMS(as.double(difftime(as.POSIXct(strptime('25-12-2013 00:00:01', 
                                      format = '%d-%m-%Y %H:%M:%S')),
                  Sys.time(), units = 'secs'))))[[1]], liHMS[[2]], liHMS[[3]]), 
                            container = christmasCountdownGroup)

ccWidget2 = gbutton("Update!", handler = function(h, ...) {
  # retrieve the old value of the ccWidget1
  oldValue = svalue(ccWidget1)
  liHMS = fnHMS(as.double(difftime(as.POSIXct(strptime('25-12-2013 00:00:01', 
                                                       format = '%d-%m-%Y %H:%M:%S')),
                                   Sys.time(), units = 'secs')))
  svalue(ccWidget1) = sprintf('%4.0f hours, %4.0f minutes, %4.0f seconds till Christmas!!',
                              liHMS[[1]], liHMS[[2]], liHMS[[3]])
  }, container = christmasCountdownGroup)

Keluaran

Berikut ini hasilnya:

masukkan deskripsi gambar di sini

tchakravarty
sumber
Itu harus terus memperbarui - itu berarti secara otomatis
Gagang Pintu
1

Dyalog APL, 61

{⎕SM[1;]←1 1,⍨⊂⍕(1 4⍴2↓2013 12 24 23 59 59 1000-⎕TS)⍪'Days' 'Hours' 'Minutes' 'Seconds'⋄∇1}1
TwiNight
sumber
0

C # 128

Golf

using D=System.DateTime;using System.Windows.Forms;class C{static void Main(){MessageBox.Show(""+(new D(2013, 12, 25)-D.Now));}}

Tidak disatukan

using D=System.DateTime;
using System.Windows.Forms;
class C
{
    static void Main()
    {
        MessageBox.Show(""+(new D(2013,12,25)-D.Now));
    }
}
James C.
sumber
1
Ini tidak terus menghitung mundur kan? Juga, Selamat Datang di codegolf!
Cruncher
Terima kasih, senang berada di sini! Saya kira saya salah paham, ini hanya akan diperbarui ketika dijalankan kembali. Saya akan mengedit dan mem-posting ulang segera
James C.
0

Python 2, 115

from datetime import datetime as d
n=d.now()
print str(24-n.day),str(23-n.hour),str(59-n.minute),str(60-n.second)

Ini menghitung baris baru sebagai 2 karakter.

Timtech
sumber