I'm building a server reporting system in Lua and C++, using the SMFL library and I've got a bit stuck on a potential issue.
The target of this script is that it creates a HTML file (with PHP within it) and uploads it to my webserver, for reporting purposes.
The name of the upload file will be '[process id][client IP][date].php', so we'll get something like '1234_199.123.45.7_31/01/2014.php', and clearly the date format needs to be in the European format.
I use the os.date("%x"), but it reports the date in the local machine's regional type, but it needs to be the dd/mm/yyyy format, regardless of the region settings of the client.
I've looked on how to do this, but I've only been able to get the time offset and not force os.date("%x") to use a specific region.
How can I forceos.date("%x") to use the dd/mm/yyyy format?
Lua's os.date accepts a format specifier, which is same as strftime. Based on strftime's docs, the format you want is obtained via
os.date("%d/%m/%Y")
You could use:
os.date("*t")
This returns a table with the date-time components, like:
With this data you can build a custom formatting function, based in T.day, T.month and T.year
Related
I want to create a new object, with a start & end date using the standard UI-bootstrap DatePicker.
I will send these date, using Ajax, to my server, where some PHP which I code will store it in a MySql database.
Coming from a PHP background, my first instinct is to store date/time as a Unix timestamp.
Since (Angular) JS has a millisecond resolution and Unix timestamps have a second resolution, that involves multiplying/dividing by 1000.
My server is returning data as a JSON, and I would rather not change that.
Ideally, I would like to do any conversion on the server, since it ought to have more processing power, and just initialze by AngularJS model fronm the JSON received.
Would it be acceptable to store the date as strings in the MySql database, rather than a timestamp? That way the downloaded data could be used unchanged to initialize the DatePicker.
Since I am having trouble getting the DatePicker to show the date which it receives from the server (as Unix timestamp), this seems like the simpler approach, but is there anything to watch out for, if I do so?
How do others do this?
We've got a collection of messy data, and trying to unify it.
Lots of services let you type dates out into different formats and they correctly understand them, but cant think what the process is called, or how we could go about doing this in PHP, if there is a library that already provides this.
So we've got time and dates in an old database we've inherited, and trying to clean it up a bit, some of the formats look like
9pm
9:00pm
25th march 2015
its a complete mix and match, does anybody know of any libraries or ways to be able to parse these into a universal format?
the problem here is the information you have is inconsistent! you need to normalize it some way, IT might actually be worth getting into an excel sheet and try to match the date time fields into some kind of regex and filter like that, is probably what i would do, so you can separate the different formats and tackle each format individually.
A program will have to first identify the format you're feeding it and then it will spit out whatever format you want!
you can use this strtotime() PHP with this to turn it into any format
http://php.net/manual/en/function.date.php
Timezones and timestamps confuses me so I'm hoping someone can answer my questions :)
Lets say I have a Python script that parses an RSS feed, converts the date value into a timestamp using the following code and stores it in a database:
article_date = parse(article.published).strftime('%s') if hasattr(article, 'published') else round(time.time())
Now when I retrieve that record from the db in PHP, and I run the following code, does PHP assume the timestamp was UTC-0 and automatically offsets the timezone to Eastern time?
date_default_timezone_set('America/New_York');
echo date('Y-m-d H:i:s',$timestamp);
I'm seeing weird issues with my dates, so I'm wondering if someone can help me out with advice on how to properly convert and store rss feed timestamps. I can across this line of code somewhere so should I put this at the top of my script?
os.environ['TZ'] = 'Europe/London'
If you want to set your timezones and keep them aligned in PHP and in Python, then your PHP code is completely correct and for python you need to apply the following:
os.environ['TZ'] = 'America/New_York'
time.tzset()
before you call strftime()
That should make sure you store the time in the same zone you're trying to retrieve it.
Note: tzset() is a Unix-only function.
In lieu of using php's date() function directly, I'd like to trigger a date format that I've created at admin/settings/date-time/formats.
At first glance I thought I could do this:
format_date(strtotime($date), 'customformat');
But it looks like format_date() has a few formats hard-coded and doesn't communicate with the date/time formats. I could use $type='custom' but that would be just like php's date() with some timezone logic. Of course I want to define date formats in one place, and use those formats in my code.
You can select in the admin interface how short, medium and long formats for format_date should look like, but you can't define extra formats like, mycustomformat.
What makes format_date different than date, is that the result is translatable. Very handy for sites that aren't english.
my site changes its locale dependent upon either user settings or browser settings (where the user hasn't set their preference). I am using amline charts, the stock chart specifically, which requires the date format in 'MM/DD/YYYY' or 'DD-MM-YYYY', I guess so the chart knows how to understand the dates. There are many ways to format a date dependent upon the computer locale, however I can't find a way to get the locale format (as above).
What's the problem?
date('m/d/Y')
or
date('d-m-Y')