Laravel中的碳数据解析问题

时间:2018-12-24 08:21:39

标签: php laravel php-carbon

我正在使用Laravel 5.6,PHP 7.2.10

2018-12-24 12:42:00.0 is getting converted to "Dec 24 2018, 12:12 pm"

修补匠的输出

$dt = App\Video::find(8611)->created_at;
=> Illuminate\Support\Carbon @1545655320 {#3075
     date: 2018-12-24 12:42:00.0 UTC (+00:00),
   }
>>> Carbon\Carbon::parse($dt)->format('M d Y, h:m a')
=> "Dec 24 2018, 12:12 pm"
>>>

我想念的或做错的是什么,或者这是碳的任何已知行为。

3 个答案:

答案 0 :(得分:1)

代替

format('M d Y,h:m a')

尝试

format('Y-m-d H:i:s.u')

答案 1 :(得分:1)

工作格式为

$dt->format('Y-m-d H:i a')

答案 2 :(得分:0)

希望可以帮助您

import android.Manifest;
import android.content.Context;
import android.content.pm.PackageManager;
import android.support.v4.app.ActivityCompat;

import com.google.android.gms.location.FusedLocationProviderClient;
import com.google.android.gms.location.LocationCallback;
import com.google.android.gms.location.LocationRequest;
import com.google.android.gms.location.LocationResult;
import com.google.android.gms.location.LocationServices;

class FusedLocationProvider {

    /*Fused API Client Objects.*/
    private FusedLocationProviderClient mFusedLocationClient;
    private LocationCallback mLocationCallback;
    private LocationRequest mLocationRequest;


    /*Listener Interface.*/
    private FusedLocationListener iFusedLocationListener;


    /*Source activity.*/
    private Context context;
    private boolean isRequestingUpdates = false;


    FusedLocationProvider(Context context, LocationRequest locationRequest) {

        this.context = context;
        mLocationRequest = locationRequest;

        /*Get FusedLocationProviderClient.*/
        mFusedLocationClient = LocationServices.getFusedLocationProviderClient(this.context);

        /*Start process of building the LocationCallback, LocationRequest.*/
        createLocationRequestCallback();
    }

    void StartLocationUpdate(FusedLocationListener iListener) {

        /*Hook the listener for callbacks.*/
        iFusedLocationListener = iListener;

        /*Check if request already ongoing.*/
        if (!isRequestingUpdates) {

            initiateLocationUpdate();
        }
    }

    void StopLocationUpdate() {

        if (isRequestingUpdates) {

            mFusedLocationClient.removeLocationUpdates(mLocationCallback);
            iFusedLocationListener.OnLocationUpdateStopped();
            isRequestingUpdates = false;
        }
    }

    private void createLocationRequestCallback() {

        mLocationCallback = new LocationCallback() {
            @Override
            public void onLocationResult(LocationResult locationResult) {

                iFusedLocationListener.OnLocationUpdate(locationResult);
            }
        };
    }


    private void initiateLocationUpdate() {

        if (ActivityCompat.checkSelfPermission(context,
                Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
            // TODO: Consider calling
            //    ActivityCompat#requestPermissions
            // here to request the missing permissions, and then overriding
            //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
            //                                          int[] grantResults)
            // to handle the case where the user grants the permission. See the documentation
            // for ActivityCompat#requestPermissions for more details.


            return;
        }

        iFusedLocationListener.OnLocationUpdateStarted();
        mFusedLocationClient.requestLocationUpdates(mLocationRequest, mLocationCallback, null /* Looper */);
        isRequestingUpdates = true;
    }
}