查找当前的英国时间

时间:2017-08-17 12:09:10

标签: vb.net datetime timezone

我正在编写一个将在美国使用的系统,但它必须参考当前的英国时间。

我需要一个离线解决方案,它会显示当前的英国时间(考虑到GMT和BST)

vb.NET中是否有内置函数可以处理这个问题,还是有一种检索此值的编程方法?

1 个答案:

答案 0 :(得分:0)

import pygame, sys
from pygame.locals import *
pygame.init()

#Initialises the music mixer and then loads the music
#file from the directory of the executable, sets the volume
#and sets it to infinite loop
pygame.mixer.init()
pygame.mixer.music.load("Wepa.mp3")
pygame.mixer.music.set_volume(0.4)
pygame.mixer.music.play(-1,0.0)
#-1 Causes an infinite loop.
#The track starts at the beginning, 0.0.

#Sets the cursor to be visible
pygame.mouse.set_visible

#Sets the FPS
FPS = 60 
fpsClock = pygame.time.Clock()

#Creates a display surface, the main window for the game, and sets a title.
DISPLAYSURF = pygame.display.set_mode((800, 600))
#Resolution of 800x600.
pygame.display.set_caption("Maths Mania")

#Creates a background colour, I used teal simply to test if it's working
#as the base colour of the window is black anyway.
TEAL = (0, 128, 128)

#Gets the title screen image from the same directory as the executable
#and sets the coordinates of the top left corner, in this case, the top left
#of DISPLAYSURF, therefore 0,0.
TitleScreen = pygame.image.load('TitleScreenButtonless.png')
Titlex=0
Titley=0

#Creates sprites for the individual buttons on the title screen and sets their top left
#corner.
PlayButton=pygame.image.load('PlayButton.png')
PlayButtonx=284
PlayButtony=235

PlayButtonHovered=pygame.image.load('PlayButtonHovered.png')
PlayButtonHoveredx=284
PlayButtonHoveredy=235

OptionsButton=pygame.image.load('OptionsButton.png')
OptionsButtonx=284
OptionsButtony=329

OptionsButtonHovered=pygame.image.load('OptionsButtonHovered.png')
OptionsButtonHoveredx=284
OptionsButtonHoveredy=329

QuitButton=pygame.image.load('QuitButton.png')
QuitButtonx=284
QuitButtony=425

QuitButtonHovered=pygame.image.load('QuitButtonHovered.png')
QuitButtonHoveredx=284
QuitButtonHoveredy=425

Intro=True
PlayClicked=False

def PlayButtonClicker(PlayButtonx,PlayButtony,width,height,action=None):
    cursor=pygame.mouse.get_pos()
    click=pygame.mouse.get_pressed()
    if (PlayButtonx+width)>cursor[0]>PlayButtonx and (PlayButtony+height)>cursor[1]>PlayButtony:
        DISPLAYSURF.blit(PlayButtonHovered, (PlayButtonx, PlayButtony))
        if click[0]==1 and action!=None:
            if action=="quit":
                pygame.quit()
                quit()

            elif action=="Playbutton":
                print("1")
                PlayClicked==True
                Intro==False

def OptionsButtonClicker(OptionsButtonx,OptionsButtony,width,height,action=None):
    cursor=pygame.mouse.get_pos()
    click=pygame.mouse.get_pressed()
    if (OptionsButtonx+width)>cursor[0]>OptionsButtonx and (OptionsButtony+height)>cursor[1]>OptionsButtony:
        DISPLAYSURF.blit(OptionsButtonHovered, (OptionsButtonx, OptionsButtony))
        if click[0]==1 and action!=None:
            if action=="quit":
                pygame.quit()
                quit()

def QuitButtonClicker(QuitButtonx,QuitButtony,width,height,action=None):
    cursor=pygame.mouse.get_pos()
    click=pygame.mouse.get_pressed()
    if (QuitButtonx+width)>cursor[0]>QuitButtonx and (QuitButtony+height)>cursor[1]>QuitButtony:
        DISPLAYSURF.blit(QuitButtonHovered, (QuitButtonx, QuitButtony))
        if click[0]==1 and action!=None:
            if action=="quit":
                pygame.quit()
                quit()

while Intro==True: #THIS IS THE MAIN GAME LOOP, EVERYTHING IN THIS LOOP IS THE GAME    

    DISPLAYSURF.fill(TEAL)
    #Fills the display window with the background colour
    DISPLAYSURF.blit(TitleScreen, (Titlex, Titley))
    #Fills the display window with the TitleScreen image and tells it
    #where to place the top left corner of said image.

    #Places the buttons on the title screen
    DISPLAYSURF.blit(PlayButton, (PlayButtonx, PlayButtony))
    DISPLAYSURF.blit(OptionsButton, (OptionsButtonx, OptionsButtony))
    DISPLAYSURF.blit(QuitButton, (QuitButtonx, QuitButtony))

    PlayButtonClicker(284,235,231,64,action='Playbutton')
    OptionsButtonClicker(284,329,231,64,action='Optionsbutton')
    QuitButtonClicker(284,425,231,64,action='Quitbutton')




#The following lines check each event that happens in the game. If any of those
#events should be to quit, the game exits.

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            quit()

#These couple lines update the display and the FPS clock.
    pygame.display.update()
    fpsClock.tick(FPS)


while PlayClicked==True:

    DISPLAYSURF.fill(TEAL)
    Nonsense=pygame.image.load('Nonsense.png')
    Nonsensex=0
    Nonsensey=0
    DISPLAYSURF.blit(Nonsene, (Nonsensex, Nonsensey))

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            quit()

    pygame.display.update()
    fpsClock.tick(FPS)

以UTC格式获取当前时间,并将其转换为英国的时间。不要被时区标识符的措辞搞糊涂,它确实涵盖了GMT和BST,以及它们之间的转换。