如何获取mydatepicker的值作为角度2的格式化值?

时间:2017-07-05 12:03:17

标签: json datepicker angular2-forms

我在angular2中使用my-date-picker,当我从datepicker中选择任何日期时,它会在JSON中为我提供datepicker的输出,就像这样 "effectiveDate":{"date":{"year":2017,"month":7,"day":1},"jsdate":"2017-06-30T18:30:00.000Z","formatted":"07/01/2017","epoc":1498847400}但我想要输出"effectiveDate":"07/01/2017"这个。

获得输出

"effectiveDate":{"date":{"year":2017,"month":7,"day":1},"jsdate":"2017-06-30T18:30:00.000Z","formatted":"07/01/2017","epoc":1498847400}

需要输出

"effectiveDate":"07/01/2017"

2 个答案:

答案 0 :(得分:0)

请尝试以下代码:

 var dateFrom = JSON.parse(JSON.stringify(this.ABIForm.controls['From'].value));   

var strFromDate =dateFrom.date.month+"/"+dateFrom.date.day+"/"+dateFrom.date.year;

var dateFromTransformed= this.datePipe.transform(strFromDate, 'yyyy-MM-dd');

答案 1 :(得分:0)

<?php
    require_once('../../Connections/Mysqli.php');
    require_once('../../webassist/mysqli/rsobj.php');
    $Recordset1 = new WA_MySQLi_RS("Recordset1", $Mysqli, 1);
    $Recordset1->setQuery("SELECT * FROM Kryptest");
    $Recordset1->execute();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>ukrypteret data</title>
    </head>
    <body>
        <p><?php echo($Recordset1->getColumnVal("Navn")); ?>  </p>
        <p><?php echo($Recordset1->getColumnVal("Password")); ?></p>
        <p>
            <?php echo($Recordset1->getColumnVal("CPR")); ?>
        </p>
    </body>
</html>
  1. 将上面的代码放在组件中以获取JSON日期格式为字符串。