Convert long to date in yii2 - yii

I have long value in
$updatedTime = 1486270800000;
This value want to convert into date as format 2015-05-25 00:10:10
Now im trying this code
echo Yii::$app->formatter->format($updatedTime, 'date');
This gives as May 22, 2014. I want to be in 2015-05-25 00:10:10 format

Updated
Try
echo Yii::$app->formatter->asDatetime($updatedTime/1000, 'php:Y-m-d H:i:s');
Above TimeStamp value will give 2017-02-05 10:30:00 ISO value.
http://www.yiiframework.com/doc-2.0/yii-i18n-formatter.html#asDatetime%28%29-detail

In your config file add this to components:
// other configs
'components' => [
// other components here
'formatter' => [
'datetimeFormat' => 'php:Y-m-d h:i:s',
],
],
when formatting the date: echo Yii::$app->formatter->format($updatedTime, 'datetime');

Related

Single log is getting split into two events

I am not using props.conf. So I guess it is the default behavior.
Below is the single log:
2018-07-19 13:30:40.293 +0000 [http8080] INFO RequestFilter- {
"transaction_id" : "aaaaaaaaawwwwwwww",
"http_method" : "POST",
"date_time" : "2018-07-19 13:30:34.694 +0000",
"requestId" : "20180719-dc7bc01d-b02c-43c8-932b-42af542ccefb"
}
But it is coming in 2 events
2018-07-19 13:30:40.293 +0000 [http8080] INFO RequestFilter- {
"transaction_id" : "aaaaaaaaawwwwwwww",
"http_method" : "POST",
And
"date_time" : "2018-07-19 13:30:34.694 +0000",
"requestId" : "20180719-dc7bc01d-b02c-43c8-932b-42af542ccefb"
}
It is always breaking from "date_time"
Any suggestions? how can i fix it?
You will need to adjust your props.conf to change the event break logic. By default, it will break whenever it detects a valid timestamp which suits most log formats.
This regex should match just the initial row:
LINE_BREAKER = \d{4}-\d{2}-\d{2}\s+\d{2}:\d{2}:\d{2}.\d{3}\s+\+\d{4}\s+\[.*\]
SHOULD_LINEMERGE = false

Cakephp3 formatting date issue in query

I am trying to format my date with this code:
$events->formatResults(function (\Cake\Datasource\ResultSetInterface $results){
return $results->map(function ($row) {
$row['date'] = date_format($row['date'],"Y-j-d");
return $row;
});
});
It seems to mostly work but I found this issue. one one field when I format this date:
2017-06-17
my result turns it into this:
"date": "2017-17-17",
Am I doing something wrong? Is this not the right way to format the date?

Logstash: modify apache date format

The grok-filter %{COMBINEDAPACHELOG} formats the timestamp as dd/MMM/YYYY:HH:mm:ss Z however I need the timestamp in the format of yyyy-MM-dd HH:mm:ss
I tried the below configuration
grok {
match => [
"message", "%{COMBINEDAPACHELOG}",
]
break_on_match => false
}
date {
match => [ "timestamp", "yyyy-MM-dd HH:mm:ss" ]
target => ["datetime"]
}
but got the below parsing error:
Failed parsing date from field {:field=>"timestamp", :value=>"19/May/2012:12:40:18 -0700", :exception=>java.lang.IllegalArgumentException: Invalid format: "19/May/2012:12:40:18 -0700" is malformed at "/May/2012:12:40:18 -0700", :level=>:warn}
Would highly appreciate if anyone can throw more light on the same.
The COMBINEDAPACHELOG pattern is expecting the date in the log entry to match the format so it can shove it into the "timestamp" field. It doesn't format your timestamp at all.
Once the date has been grok'ed out into "timestamp", you can use the date{} filter to move it into #timestamp. The pattern you supply there should match whatever's in the field.
So, pass "dd/MMM/yyyy:HH:mm:ss Z" as the format to date{} and you should be all set.
EDIT:
Based on your additional details, I was hoping that you could match each component of the input date and then combine them into a new field. That would work if you were trying to swap, say, firstName and lastName in a string, but dates are more complicated. A simple string swap wouldn't handle converting "Jan" to "01" or deal with timezones at all.
So, we're back to creating a date object and then outputting that as a string in the format you desire.
# convert "timestamp" to a date field "datetime"
date {
match => [ "timestamp", "dd/MMM/yyyy:HH:mm:ss Z" ]
target => ["datetime"]
}
# convert "datetime" to a string "datestring"
ruby {
code => "
event['datestring'] = event['datetime'].strftime('%Y-%m-%d %H:%M:%S')
"
}
For the latest version of Logstash the code would be:
# convert "datetime" to a string "datestring"
ruby {
code => "event.set('datestring', event.get('datetime').strftime('%Y-%m-%d %H:%M:%S'))"
}

Wsapi data store filter issues

I am having trouble to get my filter of a defect store working. I am trying to to get all the defect that are created after a specific date( Release.ReleaseDate ).
_getFilters: function(startDate) {
var dateFilter = Ext.create('Rally.data.wsapi.Filter', {
property: 'CreationDate',
operator: '>',
value: startDate
});
console.log('startDate is: ', startDate); //Sat Aug 23 2014 02:59:59 GMT-0400 (Eastern Daylight Time)
console.log(dateFilter.toString());
return dateFilter;
},
With the above filter, I always get an empty result, even thought I have verified that there are indeed some defects that are created after the startDate.
Note: If I remove the filter in the store config, I do see a list of defects.
Am I missing anything?
Thanks
The date has to be converted to ISO format. Assuming you got the release object:
var releaseStartDate = release.get('ReleaseStartDate');
var releaseStartDateISO = Rally.util.DateTime.toIsoString(releaseStartDate,true);
your filter will include this:
{
property : 'CreationDate',
operator : '>',
value : releaseStartDateISO
}
A full example is in this github repo.
It turns out that I need to 'reformat' the startDate to the following form before passing it to the filter.
YYYY-MM-DD

Timezone offset with logstash / redis / ES

I'm trying to configure logstash with redis and elasticsearch.
I have a problem with the #timestamp field.
The value of #timestamp is always the real event timestamp -2 hrs.
I have a shipper configured like this :
input{ file {...}}
filter{
if [type]=="apachelogs"{
grok{
match => [ "message", "%{COMBINEDAPACHELOG}"]
}
date {
locale => "en"
timezone => "Europe/Brussels"
match => [ "timestamp", "dd/MMM/yyyy:HH:mm:ss Z" ]
}
}
}
output{ redis{...}}
and a logstash-indexer like this :
input{ redis {...}}
output { elasticsearch {...}}
The result of an event in ES looks like this :
"#timestamp": "2014-05-21T13:29:53.000Z"
...
"timestamp": "21/May/2014:15:29:53 +0200"
So as you can see there is always a 2hrs offset in the #timestamp and I can't figure out why.
I've tried different things such as changing the timezone etc. without success.
Any idea about this one ?
Thanks
You can use this filter to change timezone.
Change
"#timestamp": "2014-04-23T13:40:29.000Z"
to
"#timestamp": "2014-04-23T15:40:29.000+0200"
Try to use this filter
filter {
ruby {
code => "
event['#timestamp'] = event['#timestamp'].localtime('+02:00')
"
}
}
Hope this can help you.
timezone should be work.
What's wrong with your result? Values in following two fields indicate the same time point.
"#timestamp": "2014-05-21T13:29:53.000Z"
"timestamp": "21/May/2014:15:29:53 +0200"
Where Z stands for +0000.