我正在渲染如下所示的JSON日期:import functools
from Crypto.PublicKey import RSA
from Crypto.Cipher import PKCS1_OAEP
if __name__ == '__main__':
# Encrypt
with open('public.pem', 'r') as fp:
pub = fp.read()
fp.close()
public = RSA.importKey(pub)
# tockage du fichier dans une variable rep
with open('test.csv', 'r') as fichier:
rep = fichier.read()
# liminations des spaces
rep = rep.replace(' ', '')
# ncodage pour type bytes
rep = rep.encode()
cipher = PKCS1_OAEP.new(public)
# decoupage en mot de 10 chars
rep = [rep[i:i+10] for i in range(0, len(rep), 10)]
# Open the file in binary mode so we can write bytes.
with open('encrypted.csv', 'wb') as fichier2:
for i in rep:
fichier2.write(cipher.encrypt(i))
# Decrypt
with open('private.pem', 'r') as fk:
priv = fk.read()
private = RSA.importKey(priv)
CHUNK_SIZE = 256
# Open the file in binary mode so we can read bytes.
with open('encrypted.csv', 'rb') as fichier:
# Create an iterator that will return chunks of the correct size.
chunker = iter(functools.partial(fichier.read, CHUNK_SIZE), b'')
rep = list(chunker)
cipher = PKCS1_OAEP.new(private)
with open('decrypted.csv', 'w') as fichier2:
for i in rep:
decrypted_line = cipher.decrypt(i)
fichier2.write(decrypted_line.decode())
,并且试图将其转换为/Date(1185336000000)/
类型的格式。
我尝试了一种("mmmm d, yyyy")
和一种if...includes()
方法,但是它们不起作用(语法错误),并且禁用了已渲染的数据。
format()
import firmData from '../JSON/firmDir.json';
function loadBio() {
let dateOfHire = firmData.d.results.map(function(val) {
// if (val.hiredate === null || undefined) return " ";
let newDate = val.hiredate;
if (newDate.includes('000')) {
newDate.format("mmmm d, yyyy");
}
return val.hiredate
})
$("#hireDate-id").append(dateOfHire);
}
loadBio()
答案 0 :(得分:0)
嘿,我刚刚创建了此功能-也许这对解决您的问题有帮助吗?
const date = "/Date(1185336000000)/";
function format(date:string) {
const matches = date.match(/\d+/);
const ts = matches[0];
const dateObj = new Date(ts*1);
const day = dateObj.getDay();
const month = dateObj.getMonth();
const year = dateObj.getFullYear();
return day, month, year; // returns 3 6 2007
}