碳 - 获得一个月的第一天

时间:2015-06-03 08:40:18

标签: php datetime laravel-4 php-carbon

我正在使用碳,但试图获得本月的第一天,以便我可以从月初到当天运行报告。

    $date = [
        'start' => new \Carbon\Carbon('last month'),
        'end' => new \Carbon\Carbon('today')
    ];

上述代码将显示今天的日期,回溯到上个月的同一天。但是我希望从1日到现在。

有一种简单的方法可以像上面那样做到这一点吗?无法在文档中找到任何内容。

2 个答案:

答案 0 :(得分:91)

You can use following function

class OuterController extends PreloadedFX{

    @FXML Pane rootPane;
    @FXML Stuff otherStuffBoundInFXML;
    @FXML AnchorPane innerContactPaneOne;
    @FXML Checkbox importantCheckbox;
    @FXML Label importantLabel;

    // because of 'PrealoadedFX' getting called first, 
    // you can actually inline initialize object constants
    // like this
    private final ObservableBooleanValue isSelected = importantCheckbox.selectedProperty();

    // or using an initializer
    {
        int x = 4;
        importantLabel.setText(importantLable.getText() + x);
    }

    @Inject
    public OuterController(InnerController inner, FXMLLoader loader){
        super(loader);      

        innerContactPaneOne.getChildren().add(inner.getRootView());

    }
}

class InnerController extends PreloadedFX{

    @FXML Pane innerContentPaneTwo; //this will be a child of PaneOne in OuterController
    @FXML Button otherStuff;

    @Inject
    public OuterController(FXMLLoader loader){
        super(loader);
    }

    public Node getRootView(){
        return innerContentPaneTwo;
    }    
}

//with somebody calling
OuterController rootController = injector.getInstance(OuterController.class);

答案 1 :(得分:42)

尝试

$start = new Carbon('first day of this month')

CARBON DOCS Refer #Testing Aids