I have the folling line of code which returns the hour, but how do i get hours and minutes, preferable in this format 7:45.
print(time.localtime().tm_hour)
been racking my brain for hours trying to solve this but i am only new to python lol.
Thank you in advance for your help.
Function strftime() displays the local time by default:
time.strftime('%H:%M')
#'03:34'
Related
I have been writing some code with PRAW. I want the following to give the top posts each day.But it has been returning the same ids even though new posts are submitted each day and different posts are at the top. What should I do?
import praw
reddit=praw.Reddit(client_id='id',
client_secret='secret',password='password',
user_agent='agent',username='username')
top_funny=subreddit.top(limit=1)
for submission in top_funny:
print(submission)
by default subreddit.top() returns the top of all time. You can change this by using the time_filter parameter and specify any of the following: hour, day, week, month, year, all.
ex:
subreddit.top("day", limit=1)
will return the top submission from today.
As LampToast said, you should use the time_filter.
Arguments for .top() are listed in the docs:
Parameters: time_filter – Can be one of: all, day, hour, month, week, year (default: all).
https://praw.readthedocs.io/en/latest/code_overview/models/multireddit.html#praw.models.Multireddit.top
Using momentjs, I am trying to represent tomorrow at 7:00 AM (in server time).
Something like this:
var tomorrowEarlyAm = moment().add(1, 'day').add(7, 'hour');
However, of course, adding 1 day means we are at this same time tomorrow, so adding 7 hours is basically adding 31 hours.
The difficulty is that I don't know a simple way of clipping this to midnight:
var tomorrowMidnight = moment().add(1, 'day').??
basically you can go to today's 12 AM by using .startOf('day') and then add one day .add(1, 'day') and then 7 hours .add(7, 'hour')
all to gather as bellow,
moment().startOf('day').add(1, 'day').add(7, 'hour');
as suggested by #Mat J
or you may add 31 hours directly
moment().startOf('day').add(31, 'hour');
I have an imaros script that runs each 4 minutes (using auto clicker)... but I need to it doesn't run between 23:30 to 00:30... so I need to do something like:
If (date is <23:30 and date is > 00:30) then run!!
Is this possible?
many thanks!
This is possible with JavaScript. You can create current time in JS and compare it with time between the two times you named. It's a little complicated to make. Msg me on private messages and we can work things out.
When date was 2018-03-21 19:40, i tried following code
var date = new Date();
console.log(date);
Output :
2018-03-21T16:40:53.755Z
Server is missing for 3 hours as you see. I fixed it by adding 3 hours but I think it's not a good way. How can i fix this problem with better way ?
I don't think the date is incorrect, if you look closely at the format it is being printed, it has a Z at the end, which means:
A suffix which, when applied to a time, denotes a UTC offset of 00:00;
often spoken "Zulu" from the ICAO phonetic alphabet representation of
the letter "Z".
I guess you are in a place separated by 3 hours from UTC.
Node.js uses this format to print Date objects by default, but you can print your local time using toLocaleString():
console.log(date.toLocaleString());
Your server is most likely in another time zone.
I need to define a parameter default value in a function that describes 30 days ago using report builder. What would I put in my expression? I tried using =Now()-30 but it returns the following error.
So I found the answer here
=DateAdd("d", -30, Today())