如何使用Python获取日期/时间?
使用python
查找日期/时间是什么意思提前谢谢
答案 0 :(得分:1)
您可以看到body of the message:
REGION = 'us-west-2' # or whichever
def main(queue_name):
"""Continuously poll the queue for messages (jobs)."""
sqs = boto3.resource('sqs', region_name=REGION)
queue = sqs.get_queue_by_name(QueueName=queue_name)
while True:
poll(queue=queue)
def poll(queue):
messages = queue.receive_messages() # Note: MaxNumberOfMessages default is 1.
for m in messages:
process_message(m)
def process_message(message):
print(message.body)
# ...
if success: # processed ok
message.delete() # remove from queue
else: # an error of some kind
message.change_visibility(VisibilityTimeout=1) # dead letter or try again
我通常使用以下代码段执行此操作:
//var form = document.getElementsByTagName("form")[0];
//form.setAttribute("method", "POST");
var data = JSON.parse(localStorage.getItem('data'))
if (data == null) {
data = new Array();
}
var add = document.getElementsByTagName("button")[0];
add.setAttribute("onclick", "validate()");
//console.log(add);
function remove(obj) {
console.log(data);
var item_to_delete = obj.id;
data.splice(item_to_delete,1);
console.log(data);
console.log(obj.id);
localStorage.setItem("data", JSON.stringify(data))
location.reload();
}
function validate() {
var age = document.getElementsByName("age")[0].value;
var relation = document.getElementsByName("rel")[0].value;
var is_smoker = document.getElementsByName("smoker")[0].checked
if (is_smoker) {
smoker = "Yes";
}
else {
smoker = "No";
}
if (age.length == 0 || relation == "") {
alert ("Please fill out the form")
}
else {
var myObj = {"age": age, "relation": relation, "smoker":smoker};
data.push(myObj);
localStorage.setItem("data", JSON.stringify(data))
}
}
var debug = document.getElementsByTagName("ol")[0];
//console.log(debug)
for (var i = 0; i < data.length; i++) {
debug.innerHTML += "<li id = '" + i + "' onclick = 'remove(this)'>Age: " +
data[i].age + " ||| Relationship: " +
data[i].relation + " ||| Smoker? " +
data[i].smoker + "</li>"
}
答案 1 :(得分:0)
您的代码适用于我。这是我看到的输出(打印json.dumps(message,indent = 4)),如果我运行代码然后将消息发送到我的SQS队列:
{
"Messages": [
{
"Body": "Hello Jo Ko!",
"ReceiptHandle": "redacted",
"MD5OfBody": "redacted",
"MessageId": "redacted"
}
],
"ResponseMetadata": {
"RetryAttempts": 0,
"HTTPStatusCode": 200,
"RequestId": "redacted",
"HTTPHeaders": {
"x-amzn-requestid": "redacted",
"content-length": "800",
"server": "Server",
"connection": "keep-alive",
"date": "Wed, 17 May 2017 16:00:00 GMT",
"content-type": "text/xml"
}
}
}
PS botocore SQS receive_message方法不返回消息。它返回一个包含一系列消息的字典。
答案 2 :(得分:0)
您可以使用datetime.now
作为当地时间。对于UTC / EST / WIB等,您可以将时间格式更改为epoch(unix)以用于时差,然后再放回所需的格式。
from datetime import datetime
from datetime import timedelta
local_time = datetime.now()
utc_time = datetime.now() - timedelta(hours=8)
est_time = datetime.now() - timedelta(hours=12)
wib_time = datetime.now() - timedelta(hours=1)
pst_time = datetime.now() + timedelta(hours=9)
wat_time = datetime.now() - timedelta(hours=9)
fmt = '%a, %Y/%m/%d,%H:%M'