整数值不正确:' time()'对于列' created_on'

时间:2017-12-24 11:05:49

标签: php mysql codeigniter

我正在尝试以时间戳格式检索codeigniter中的当前时间和日期。以下是几行代码。

 $data = array(
        'username' => $username,
        'password' => $password,
        'email' => $email,
        'ip_address' => $ip_address,
        'created_on' => time(),
        'date_created' => time(),
        'active' => '1',
        'user_type_id' => '2'
    );

这里,在created_on列中,我希望以时间戳格式获得当前日期和时间的值。 帮助将不胜感激。

2 个答案:

答案 0 :(得分:1)

你可以尝试:

$this->db->set('created_on', time(), false);

表示带有时间戳的字段,并将它们从数据数组中删除。

答案 1 :(得分:0)

你可以试试这个

public class ScreensController extends StackPane {

    private HashMap<String, Node> screens = new HashMap<>();
    private Client client;
    private NewTransactionController newTransactionController;
    private BankAccountController bankAccountController;
    private ManageBanksController manageBanksController;

    public Client getClient() {
        return this.client;
    }

    public NewTransactionController getNewTransactionController() {
        return this.newTransactionController;
    }

    public BankAccountController getBankAccountController() {
        return this.bankAccountController;
    }

    public ManageBanksController getManageBanksController() {
        return this.manageBanksController;
    }

    public ScreensController() {
        try {
            this.client = new Client();
            System.out.println("Client: Client created");
        } catch (RemoteException e) {
            System.out.println("Client: Cannot create Client");
            System.out.println("Client: RemoteException: " + e.getMessage());
            System.exit(0);
        }
    }

    public void addScreen(String name, Node screen) {
        screens.put(name, screen);
    }

    public void loadScreen(String name, String resource) {
        try {
            FXMLLoader myLoader = new FXMLLoader(getClass().getResource(resource));
            Parent loadScreen = myLoader.load();
            IControllers myScreenController = myLoader.getController();
            if (myScreenController instanceof NewTransactionController) {
                this.newTransactionController = (NewTransactionController) myScreenController;
            } else if (myScreenController instanceof BankAccountController) {
                this.bankAccountController = (BankAccountController) myScreenController;
            } else if (myScreenController instanceof ManageBanksController) {
                this.manageBanksController = (ManageBanksController) myScreenController;
            }
            myScreenController.setScreenParent(this);
            addScreen(name, loadScreen);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void setScreen(final String name) {
        if (screens.get(name) != null) {
            if (!getChildren().isEmpty()) {
                getChildren().remove(0);
                getChildren().add(0, screens.get(name));
                ClientMain.setProperties(name);
            } else {
                //First time start up
                getChildren().add(screens.get(name));
                ClientMain.setProperties(name);
            }
        } else {
            System.out.println("Screen hasn't been loaded!!!");
        }
    }
}
date("Y-m-d"); // this will show the data in the format year-month-day
date("H:i:s"); // this will show the data in the format 14:36:55