Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a date string (event occurrence) in local time (scraped from a web page using Scrapy) and I need to convert it to a timestamp. I do this using:

return int(time.mktime(time.strptime(dateString, "%Y-%m-%d")))

That gives me a time stamp that I store in my database. Every day I scrape the page for new data so I need to compare dates. I use the same function as above to convert to a timestamp that I compare with the timestamp in the database. This way I avoid duplicate records.

When I run this script locally (scheduled task) everything works as expected. However, when I run it on a remote server the conversion results in a different timestamp which means I end up with duplicate records. This is because I have pre-populated my database locally.

In my app which needs to display the actual date that the event occurred i have the following:

 /**
 * @summary Format date string
 *
 * @param date {Integer} Unix time stamp
 *
 * @return date {String}
 */
function formatDate( date ) {
    var m_names = new Array( "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ),
        d = new Date( date ),
        curr_date = d.getUTCDate(),
        curr_month = d.getUTCMonth(),
        curr_year = d.getUTCFullYear();

    return curr_date + "-" + m_names[ curr_month ] + "-" + curr_year;
}

Since my app can display records (events) in several timezones at the same time, I need to ensure that the event date is correctly displayed.

I need some advice on how I can best achieve the desired result.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
275 views
Welcome To Ask or Share your Answers For Others

1 Answer

Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...