嗨,我不确定这个等式是否正确,因为我不确定日期。我知道它返回相同的日期,但我正在尝试学习不同的格式以及如何添加不同日期的日期。我知道可能不是编写代码的最佳方式,我仍然想知道如何编写这段代码。等式是:
$mhYr + ($vSDday -1day)
My code:
$date = "2015-11-02";
$vStartDate = strtotime($date);
$currentdate = $vStartDate;
$vSDday = date('d', $currentdate); //day
$monthY = date('m', $currentdate); //Month
$mhYr = date("01-$monthY"); //first day of any month
但由于约会我一直都会收到错误。
一个例子是1stOfMonth +(daysOfStartDate -1天)。因此,如果我在11月2日开始,我想表演:11月1日+(2 - 1天)。但我不知道如何把所有这些放在一起。
答案 0 :(得分:0)
当你这样做时:
#!/usr/bin/python2
import binascii
from getpass import getpass as getpasswd
try:
from Crypto.Cipher import Blowfish as bfcipher #blowfish encryption
except ImportError:
print("* Install pycrypto *")
exit(2)
def get_enctype_user():
ask_enctype = '''
** Crypy **
Choose encryption
[1] Blowfish
--> '''
try:
enctype = int(raw_input(ask_enctype))
except ValueError:
print("Non-integer value!")
exit(4)
if enctype == 1:
return 1
else:
print("Non-valid option")
exit(1)
def autopadding(__txt):
rlen = len(__txt)%8
__txt = __txt +(" "*(8-rlen))
return __txt
def get_operation_user():
ask_operation = '''
** What to-do
[1] Encrypt
[2] Decrypt
--> '''
try:
optype = int(raw_input(ask_operation))
except ValueError:
print("Non-integer value!")
exit(4)
if optype == 1:
return 1
elif optype == 2:
return 2
else:
print("Non-valid operation")
exit(1)
class BlowfishCipher:
def __init__(self, __txt, __passwd):
self.encpasswd = __passwd
self.text = __txt
self.coder = bfcipher.new(self.encpasswd)
def crypt(self):
self.encrypt = self.coder.encrypt(self.text)
return self.encrypt
def decrypt(self):
self.decrypt = self.coder.decrypt(self.text)
return self.decrypt
def main():
encryption = ""
operation = ""
__text = ""
__passwd = ""
use_enc = get_enctype_user()
if use_enc == 1:
encryption = "blowfish"
user_op = get_operation_user()
if user_op == 1:
operation = "crypt"
elif user_op == 2:
operation = "decrypt"
print("[---------]")
__text = str(raw_input("Type text: "))
__passwd = getpasswd("Type password: ")
pad_text = autopadding(__text)
if encryption == "blowfish":
bfch_obj = BlowfishCipher(pad_text, __passwd)
if operation == "crypt":
encrypted_text = bfch_obj.crypt()
print("Encrypted text: "+encrypted_text)
elif operation == "decrypt":
decrypted_text = bfch_obj.decrypt()
print("Decrypted text: "+decrypted_text)
if __name__ == "__main__":
try:
main()
except KeyboardInterrupt:
print("Bye bye!")
exit(0)
except Exception:
print("General exception raised!")
exit(3)
并尝试打印它( $date = "2015-11-02";
$vStartDate = strtotime($date);
),它将在1970年1月1日午夜和 2015-11之间打印秒的数量差异-02 ,要将时间转换为您需要的人类可读格式 echo $vStartDate
,它将返回收集格式。
getdate($vStartDate )
然后你就可以开始了:
$date = "2015-11-02";
$vStartDate = strtotime($date);
$timeCollection= getDate($vStartDate);