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');
Related
I am doing a simple query to retrieve data via ODBC and OdbcDataReader. However, I am not able to determine what the time zone of the data returned is. I have checked every doc and nothing tells me what it is (UTC or local). I tried to look for a setting in SQL Plus and was unable to find something there either.
Does anyone know or know what docs would say? Thanks!
#Madgui is correct with the timezone information. However, there was something else I wanted to mention.
In SQLplus, if you use SELECT ISO8601(IP_TREND_TIME) in your query, you will be returned an ISO8601 string.
If you are doing something in let's say C# and need this as a UTC time, you would have to do the following:
DateTime.SpecifyKind(DateTime.Parse(datareader["TREND_TIME"].ToString()).ToUniversalTime(), DateTimeKind.Utc)
DateTim.Parse will return as a LOCAL time, just an FYI which is why you need to to the .ToUniversalTime(). Also, never a bad idea to classify as UTC.
In AspenTech IP21 SqlPlus, every timestamps you are relevant to server timezone. If you are only interested in UTC offset (beware, timezone is not just that), you can ask the server its current time, and do the calculation:
--something like that :
WRITE GETDBTIME;
Also, if you have right on the server, you could call a system command (check the doc for the correct syntax) to have the name of the Timezone:
SYSTEM 'tzutil /g';
The best way to work using timezones in InfoPlus is ever use the function ISO8601(timestamp here). This way you avoid timezones conversions mistakes.
I need to create a PDF with a date field that displays dates in the format dd.mm.yyyy. This field must be validated and should also accept inputs in other formats.
For example, users should be able to input dates in the form dd.mm.yy, which will then be expanded to dd.mm.20yy (MS Office apps like Excel do this).
Alternatively, selecting multiple valid formats would be an acceptable solution.
What currently happens:
If the date format of the field is set to dd.mm.yyyy, dd.mm.yy is rejected.
If the date format of the field is set to dd.mm.yy, dd.mm.yyyy is accepted (but formatted to dd.mm.yy).
The last behaviour is almost what i need, just with the wrong format.
Is there a way to do this without custom Javascript? If not, is there a way to still use the built-in formatting or do i have to rewrite everything in JS?
Unfortunately this is not achievable with Acrobat's built-in formatting.
One thing to add to your second bullet point: it trims the date down to .yy when you exit the field, but it still retains all four digits. When you click into the field, it will revert back to being .yyyy. That may or may not matter depending on how you're using it.
Regarding a custom validation, a quick Google search will yield an abundance of Javascript date validation scripts. Something like this could probably be quickly repurposed for your application.
Is there a way to convert timezones like "America/Los_Angeles" to timezone shortname "PDT" in ruby?
The abbreviations are typically contextual - so "PDT" only applies while daylight saving time is in operation.
Judging by the documentation, if you format a Time with strftime and use a format string of %Z, you should get the time zone abbreviation.
Personally I dislike using the abbreviations, given that they're ambiguous and can cause a lot of confusion. (I've seen people using "PST" year-round, for example, referring to "7/20/2012 9:00 PST" for example - a date/time which makes no sense.) That's a different matter though :)
More explicit answer:
Time.now.in_time_zone("America/Los_Angeles").strftime('%Z')
Recently,I am handling a solution for WebPart internationalization,but I am not familiar with the culture or habits in different regions.So I am asking for some information if you are glad to help.
Suppose I am a different person in another region,for example,a German.I am using the SharePoint,which is a German edition.So,
1) What's the input habit of me?
For example,if I need to input "10000",will I input "10.000,00" or just "10000"?Which is frequent to the user?
2) How to handle the "Date" and "Time" format?
I think it's better if I can select the date or time instead of inputing the date or time string.
3) Any information that you think will be helpful to me?
That is very kind of you,thanks for your help!
To be honest, I am not sure how you want to handle i18n, but I am assuming that you want to do this on the client side.
In this case, I can recommend using Globalize for formatting (both numerical values and date/time could be handled this way).
As for parsing dates (that is handling dates provided by user), there is actually even easier way - just use jQuery UI Datepicker with valid regional script. Obtaining Date object is as easy as calling Datepicker's getDate method.
For my application, I'm importing the calendar event from google calendar. The only problem which I'm facing is Time zone list. I'm getting the timezone as output from google calendar xml, which I have to check with time zone list and add time accordingly... so from where I can get this standard time zone list.. or some other alternative to achieve the same.
If you're using Java, use Joda Time - the time zone ID given by Google Calendar will be one the Joda Time understands. The standard TimeZone class may well understand it too, but I think Joda is more likely to.
Assuming you're seeing all the VTIMEZONE stuff that goes along with the event, you can ignore the details - just use the ID.
Unfortunately there are some time zone IDs which have changed over time - I can't remember any examples off-hand, but you may need to do some translations if you're provided with the "old" names.
If you're using .NET, you really need to be using .NET 3.5 and the TimeZoneInfo class. Unfortunately that uses Windows names instead of Olson IDs, but there's a translation list available somewhere (I can dig it out if you want).
If you're not using either of these platforms, you basically need to find a library which supports Olson Zoneinfo names. (That wikipedia article has some helpful links at the bottom.)
I would definitely try to find a library which will be able to give you the relevant information based on an ID, rather than using the rules given back in the calendar entry. Time zones change over time, and the zoneinfo database contains historical and future information, but that can't be easily encoded in the calendar entry.
There are some good articles about working with Erlang date/time libraries here:
http://www.trapexit.org/Category:DateTimeRecipes
Hope it helps.
Check out these function
calendar:datetime_to_gregorian_seconds({Date, Time})
calendar:gregorian_seconds_to_datetime(Seconds) -> {Date, Time}
Converting to "gregorian seconds" and correcting the timezone-offset and converting back to date form is half the solution.
There is no library to access timezone datafiles in Erlang/OTP, and as far as I know there is no third part library to get at it either. So your options are to yourself convert the available timezone databases to something usable from Erlang, or to settle for just knowing a few of them.
You know, unless you want to start a project to read timezone data in Erlang. :-)