显示下周四的日期

时间:2017-11-23 11:35:09

标签: php date timestamp strtotime

我使用以下代码显示每个下一个星期四的日期。

现在我遇到了以下问题:今天是星期四,但我不想显示下周的日期,直到当天结束。怎么可能?

每个星期四我们都有工作时间从晚上7点到晚上10点。因此,我需要显示今天的日期。晚上10点以后我可以显示下一个星期四的日期(例如30.11。)

当前代码:

 $timestmp = strtotime('next thursday');
 setlocale(LC_TIME, "de_DE");
 $next = strftime('%A, %d.%m.%Y', $timestmp); 

4 个答案:

答案 0 :(得分:1)

  

if(date(' l')==' Thursday'){   回声'今天是星期四! Whola&#39!;   }   其他{   $ timestmp = strtotime('下周四');    setlocale(LC_TIME," de_DE");   $ next = strftime('%A,%d。%m。%Y',$ timestmp);   }

答案 1 :(得分:1)

您可以使用简单if condition来检查今天是星期四,打印今天的日期。否则,请在下周四打印

setlocale(LC_TIME, "de_DE");

if (date('l') == 'Thursday') {
    $thu = strftime('%A, %d.%m.%Y');
} else {
    $timestmp = strtotime('next thursday');
    $thu = strftime('%A, %d.%m.%Y', $timestmp);
}

echo $thu;

答案 2 :(得分:0)

所以你今天想要今天这个节目吗? 然后转到昨天的时间戳strtotime。像那样

import tkinter as tk
from tkinter import font as tkfont
import tkinter.messagebox as messagebox
import random
import time

global strength
global gen
strength = 0
gen = '[password will be here]'

def generate():
    alphabet = "abcdefghijklmnopqrstuvwxyz"
    pw_length = 8
    mypw = ""

    for i in range(pw_length):
        next_index = random.randrange(len(alphabet))
        mypw = mypw + alphabet[next_index]

    # replace 1 or 2 characters with a number
    for i in range(random.randrange(1,3)):
        replace_index = random.randrange(len(mypw)//2)
        mypw = mypw[0:replace_index] + str(random.randrange(10)) + mypw[replace_index+1:]

    # replace 1 or 2 letters with an uppercase letter
    for i in range(random.randrange(1,3)):
        replace_index = random.randrange(len(mypw)//2,len(mypw))
        mypw = mypw[0:replace_index] + mypw[replace_index].upper() + mypw[replace_index+1:]

    print(mypw)
    return mypw

class SampleApp(tk.Tk):
    def __init__(self, *args, **kwargs):
        tk.Tk.__init__(self, *args, **kwargs)

        self.title_font = tkfont.Font(family='Helvetica', size=18, weight="bold", slant="italic")

        # the container is where we'll stack a bunch of frames
        # on top of each other, then the one we want visible
        # will be raised above the others
        container = tk.Frame(self)
        container.pack(side="top", fill="both", expand=True)
        container.grid_rowconfigure(0, weight=1)
        container.grid_columnconfigure(0, weight=1)

        self.frames = {}
        for F in (StartPage, PageOne, PageTwo):
            page_name = F.__name__
            frame = F(parent=container, controller=self)
            self.frames[page_name] = frame

            # put all of the pages in the same location;
            # the one on the top of the stacking order
            # will be the one that is visible.
            frame.grid(row=0, column=0, sticky="nsew")

        self.show_frame("StartPage")

    def show_frame(self, page_name):
        '''Show a frame for the given page name'''
        frame = self.frames[page_name]
        frame.tkraise()

class StartPage(tk.Frame):
    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)
        self.controller = controller
        label = tk.Label(self, text="Password program", font=controller.title_font)
        label.pack(side="top", fill="x", pady=10)

        button1 = tk.Button(self, text="Check your password strength",
                        command=lambda: controller.show_frame("PageOne"))
        button2 = tk.Button(self, text="Generate a new password",
                        command=self.generate_password)
        button3 = tk.Button(self, text="quit", command=close)

        button1.pack()
        button2.pack()
        button3.pack()

    def generate_password(self):
        password = generate()
        password_var = self.controller.frames['PageTwo'].var
        password_var.set(password)
        time.sleep(0.1)
        self.controller.show_frame("PageTwo")

class PageOne(tk.Frame):
    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)
        self.controller = controller
        label1 = tk.Label(self, text="Check your password", font=controller.title_font)
        label1.pack(side="top", fill="x", pady=10)
        entry = tk.Entry(self, bd =6)
        button2 = tk.Button(self, text="Back",
                       command=lambda: controller.show_frame("StartPage"))
        label2 = tk.Label(self, text="Strength:", font=controller.title_font)
        label3 = tk.Label(self, text=strength, font=controller.title_font)
        entry.pack()
        button2.pack()
        label2.pack()
        label3.pack()

        password = list(entry.get())

class PageTwo(tk.Frame):
    def __init__(self, parent, controller):
        self.var = tk.StringVar()
        self.var.set(gen)

        tk.Frame.__init__(self, parent)
        self.controller = controller
        label1 = tk.Label(self, text="Generate a password", font=controller.title_font)
        label1.pack(side="top", fill="x", pady=10)
        label2 = tk.Label(self, textvariable=self.var, font=controller.title_font)
        button = tk.Button(self, text="Back",
                       command=lambda: controller.show_frame("StartPage"))
        label2.pack()
        button.pack()

def close():
    messagebox.showinfo("BYE", "Thank you")
    time.sleep(1)
    app.destroy()

if __name__ == "__main__":
    app = SampleApp()
    app.mainloop()
    generate()

然后它将从昨天开始寻找下一个星期四,即今天。

答案 3 :(得分:0)

如果星期日,星期一,星期二或星期三,下面的代码会抓住下一个星期四。如果它是firday或星期六,它会抓住最后一个星期四。如果今天是星期四的话,那将会抓住当天。

length($0)