I'm currently writing a program in Ruby in which I've to get the current time (from my machine). The problem in here is, that I'm two timezones ahead and just decrement the hours by 2.
GMT+2 - 2 = GMT+0
Now my question would be, if there's any smarter way in doing so?
I wasn't able to find anything.
Just to give another example from another language:
date_default_timezone_set('GMT+0');
It sets the default timezone to GMT+0, but I guess it's kinda self explanatory. :)
Found it:
t = Time.now.getlocal('+00:00')
Related
I'm a very, very n00b developper learning Python at university (I started a few weeks ago really) and I'm on my first assignment. Everything's going well, except one thing and i just can't figure it out. Or rather, I know what the problem is, but I can't find the solution. In short, I need to ask the user to input a number, and if number is 0, then the programs shows a message and stops there. Otherwise, it goes on with asking more info and uses For loops. My question is: How do I insert lines that are not part of the IF (user has entered 0) but also not part of any For loops (i don't want these lines repeated). I'm not sure if that makes any sense.
python code
basically i want the last print to be shown if the user has entered more than 0 in the beginning, but not be shown if the user has entered 0. I'm not showing the actual code, since it's a uni assignment, but the screenshot shows exactly the issue I'm having with the real code :) Thanks for your help!! (also, sorry that it's actually a link, because i don't have enough points yet to embed the image).
This one is pretty easy. Im not that great at python yet but i just tested it and it works as intended.
def isZero(val):
if val==0:
print('bye')
quit()
title = int(input('enter a number'))
ZeroCheck = isZero(title)
while title>0:
title = int(input('enter a number'))
isZero(title)
I was making a discord bot and I want to make an account system, what my program supposed to do is to keep on finding a registered user by checking on the .json file over and over until it finds the two variable with the same value, problem is I can't find anything online for a solution. I just need a code for it :)
Sure! Try something like this:
with open('filenamehere', 'r') as f:
# Add Code to add values to a list called x here
After this, we can go ahead and do one of two things:
Run a simple if value is in list x, or
Run a for loop on the list until it reaches the value required.
Either way should give you the desired outcome. Sorry I was a little vague, your question was as well.
I have unix timestamp in table, wants to show to user using Carbon. How can I achieve ?
e.g.
1487663764.99256 To
2017-02-24 23:23:14.654621
Did you check the carbon docs? I think this is what youre looking for:
Carbon::createFromTimestamp(-1)->toDateTimeString();
Checkout http://carbon.nesbot.com/docs/#api-instantiation
There are several ways to create Carbon instances described in the Carbon documentation, which is linked at the bottom of the project's README. The relevant section is this:
The final two create functions are for working with unix timestamps. The first will create a Carbon instance equal to the given timestamp and will set the timezone as well or default it to the current timezone. The second, createFromTimestampUTC(), is different in that the timezone will remain UTC (GMT). The second acts the same as Carbon::createFromFormat('#'.$timestamp) but I have just made it a little more explicit. Negative timestamps are also allowed.
So you can just do:
$carbon = Carbon::createFromTimestamp($dbResult['SomeTimestampColumn']);
If you really love your fluid method calls and get frustrated by the extra line or ugly pair of brackets necessary when using the constructor you'll enjoy the parse method:
Carbon::parse(1487663764);
Carbon::parse('first day of next month');
For date ranges, I currently use this format (until precise specifications come up):
<time datetime="2012-11">November 2012</time> - <time datetime="2013-01">January 2013</time>
I was wondering if there is, or will be, a way to indicate today's date. I mean, I know we can do this:
<time datetime="2013-03-05">Today</time>
but I would like to have something like this:
<time datetime="now">Today</time>
If not, I plan to leave the "Today" word with no extra markup. Would you recommend a better solution?
Thanks!
EDIT: To add bit of context, I am building an online resume, hence the date ranges as well as the ones that involve: <time datetime="yyyy-mm">[Month] [Year]</time> - Present.
Thanks everyone for your efforts.
Just to clarify things, I was not looking for ways to dynamically update the content of the datetime attribute. I just wanted to know if there was a way to semantically indicate the "present" day or time.
The answer is: no, there is no way to do that.
I do believe that there might be a change someday. Some of you wondered when this could be useful. I agree that currently there is no need for that, but there might be ways to indicate date ranges in the future specs (the <time> element is still in draft, after all). If so, there could be ranges that start at a precise point and that are still going, giving a use case for a "present"/"now"/... keyword, IMO.
Try using php or JavaScript to get the local time from the user's computer, then output that as text. See http://php.net/manual/en/function.localtime.php for instructions on doing it with php.
EDIT: It gets the server time, not the user's time. To get the user's time, you have to use javascript.
surfing the web i found this question, i thought it would be cool to answer since today we have an answer to that.
<time datetime="P4DT4H3M">four days, and three minutes</time>
To better understand you can see here:
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/time
I would like to get a current date time with erlang.
I have tried using the code below;
{{Year,Month,Day},{Hour,Min,Sec}} = erlang:localtime().
But sometimes it got an error like '** exception error: no match of right hand side value {{2012,5,6},{23,40,58}}'
Looks like there is a problem with 1 digit. I try searching couple of webs but still cannot find a way to cope this.
I believe this is quite an easy one but as a erlang newbie, I cannot resolve this. I try my best.
Env:
Erlang {"OTP APN 181 01","R15B01"} installed with windows binary version
Windows XP
Thanks in advance,
No, there is no problem with 1 digit. It should match perfectly well (check with {{Year,Month,Day},{Hour,Min,Sec}} = {{2012,5,6},{23,40,58}}). Most likely you have already assigned one of the variables to something earlier in the function.