我有:
import tkinter as tk # PEP8: `import *` is not preferred
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BOARD)
GPIO.setup(8, GPIO.OUT)
GPIO.output(8, False)
button_pressed = False # PEP8: preferred `lower_case_names`
# --- functions ---
def on_press(event):
global button_pressed
button_pressed = True
GPIO.output(8, True)
def on_release(event):
global button_pressed
button_pressed = False
GPIO.output(8, True)
# run after 500ms (0.5s) instead of `sleep`
master.after(500, blink_off)
def blink_off():
if not button_pressed:
GPIO.output(8, False)
# run after 500ms (0.5s) instead of `sleep`
master.after(500, blink_on)
def blink_on():
if not button_pressed:
GPIO.output(8, True)
# run after 500ms (0.5s) instead of `sleep`
master.after(500, blink_off)
# --- main ---
master = tk.Tk()
button = tk.Button(master, text="Turn on light")
button.pack()
# here "button" means "tk.Button" and "Button" means "mouse left button"
button.bind('<ButtonPress>', on_press) # mouse left button pressed on tk.Button
button.bind('<ButtonRelease>', on_release) # mouse left button released on tk.Button
# start blinking - it will use `after()` to loop
blink_on()
master.mainloop()
我尝试过:
Thu Apr 23 2020 00:00:00 GMT+0200 (Ora legale dell’Europa centrale)
但这不是正确的
我在看dateStart = new Date(dateStart);
答案 0 :(得分:1)
类似
const dateStart = new Date('Thu Apr 23 2020 00:00:00 GMT+0200');
const formatted = `${dateStart.getDate()}/${dateStart.getMonth() + 1}/${dateStart.getFullYear().toString().substr(-2)}`
答案 1 :(得分:1)
如果,当您考虑操作Date
对象时,您会想到MomentJ ... ...不要着急! you might not even need就是66Kb,这很简单! ?
对于您来说,这很简单:
由于您已经拥有date()
对象reading the docs,因此您可以访问日期的所有部分,尽管getMonth()
有点奇怪?♂️
如此:
var dateStart = new Date()
var dateAsString = `${dateStart.getDate()}/${dateStart.getMonth()+1}/${dateStart.getFullYear().toString().substr(-2)}`
console.log(dateAsString)
答案 2 :(得分:0)