格式化日期angularjs ui-grid

时间:2015-08-10 21:07:30

标签: angularjs angular-ui-grid

我正在尝试更改日期的显示方式。 数据以#34; Sun May 03 18:04:41 2009"

格式的字符串形式出现

我查看了这些示例,他们要我使用

$scope.gridOptions = {
  data: 'mydata',
  enableRowSelection: true,
  multiSelect: false,
  enableColumnResize: true,
  columnDefs: [
    { field: 'startDate', displayName: 'Date', cellFilter: 'date:\'yyyy-MM-dd\'' }]
};
然而,这对我不起作用。数据仍然按原样显示。而不是" 2009-05-13"我做错了什么?提前谢谢!

3 个答案:

答案 0 :(得分:46)

使用:输入:'date',        cellFilter:'date:\'MM / dd / yyyy \''

$scope.gridOptions = {
data: 'mydata',
enableRowSelection: true,
multiSelect: false,
enableColumnResize: true,
columnDefs: [
{ field: 'startDate', displayName: 'Date',type: 'date', cellFilter: 'date:\'yyyy-MM-dd\'' }]};

答案 1 :(得分:11)

您似乎正在尝试使用与Angular date filter不兼容的日期格式。文档说它需要是Date对象,毫秒或ISO 8601日期。由于您的日期字符串与其中任何一个都不匹配,因此您需要滚动自己的字符串格式化程序或将该值转换为Date对象或毫秒,然后再将其传递给日期过滤器。

答案 2 :(得分:1)

使用 ?php /** * The Header for our theme * * Displays all of the <head> section and everything up till <div id="main"> * * @package WordPress * @subpackage Twenty_Fourteen * @since Twenty Fourteen 1.0 */ ?><!DOCTYPE html> <!--[if IE 7]> <html class="ie ie7" <?php language_attributes(); ?>> <![endif]--> <!--[if IE 8]> <html class="ie ie8" <?php language_attributes(); ?>> <![endif]--> <!--[if !(IE 7) | !(IE 8) ]><!--> <html <?php language_attributes(); ?>> <!--<![endif]--> <head> <meta charset="<?php bloginfo( 'charset' ); ?>"> <meta name="viewport" content="width=device-width"> <title><?php wp_title( '|', true, 'right' ); ?></title> <link rel="profile" href="http://gmpg.org/xfn/11"> <link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>"> <!--[if lt IE 9]> <script src="<?php echo get_template_directory_uri(); ?>/js/html5.js"> </script> <![endif]--> <?php wp_head(); ?> <script src="http://code.jquery.com/jquery-latest.min.js"></script> <script src="<?php echo get_template_directory_uri(); ?>/js/bjqs-1.3.min.js"></script> <script src="<?php echo get_template_directory_uri(); ? >/js/owl.carousel.min.js"></script> <link type="text/css" rel="Stylesheet" href="<?php echo get_template_directory_uri(); ?>/bjqs.css" /> <link type="text/css" rel="Stylesheet" media="print" href="<?php echo get_template_directory_uri(); ?>/print.css" /> <?php if (is_single()) { global $post; $cat=''; $cats = get_the_category($post->ID); foreach ( $cats as $c ) { $cat .= $c->category_nicename.' '; $catClass = 'category-'.$cat; } } ?> <!-- //Facebook Pixel --> <script>(function() { var _fbq = window._fbq || (window._fbq = []); if (!_fbq.loaded) { var fbds = document.createElement('script'); fbds.async = true; fbds.src = '//connect.facebook.net/en_US/fbds.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(fbds, s); _fbq.loaded = true; } _fbq.push(['addPixelId', '862151620502417']); })(); window._fbq = window._fbq || []; window._fbq.push(['track', 'PixelInitialized', {}]); </script> <noscript><img height="1" width="1" alt="" style="display:none" src="https://www.facebook.com/tr?id=862151620502417&amp;ev=PixelInitialized" /> </noscript> </head> <body <?php body_class($catClass); ?>> <script> (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o) [0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) }) (window,document,'script','//www.googleanalytics.com/analytics.js','ga'); ga('create', 'UA-55236663-1', 'auto'); ga('send', 'pageview'); </script> <div id="fb-root"></div> <script>(function(d, s, id) { var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) return; js = d.createElement(s); js.id = id; js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=430603427072800"; fjs.parentNode.insertBefore(js, fjs); }(document, 'script', 'facebook-jssdk'));</script> <div class="headerWrapper"> <?php $getTheSwatch = get_post_meta($post->ID,'colorSwatch',true); ?> <div class="header-main swatch<?php echo $getTheSwatch; ?>"> <div id="site-header"> <a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home" title="Feincook - Let's cook better!"> <img src="<?php bloginfo('template_url'); ?>/images/headerLogo.jpg" alt="Feincook - Let's cook better!"> </a> <div class="blogBaloon"></div> </div> <div class="socialLinksHolder"> <ul class="socialLinks"> <li><a class="facebookLink" href="https://www.facebook.com/FeinCook" target="_blank"></a></li> <li><a class="youtubeLink" href="https://www.youtube.com/channel/UCe3HkTlwmXCmg-CmUVZwSqQ" target="_blank"> </a></li> <li><a class="instagramLink" href="http://instagram.com/feincook" target="_blank"></a></li> <li><a class="mailLink" href="mailto:<?php echo 'info@';echo 'feincook.co.il'; ?>" target="_blank"></a></li> </ul> <form role="search" method="get" class="search-form" action="<? php echo home_url( '/' ); ?>"> <label> <span class="screen-reader-text">Search for:</span> <input type="search" class="search-field" placeholder="חפש באתר" value="" name="s" title="Search for:" /> </label> <input type="submit" class="search-submit" value="Search" /> </form> <?php global $userdata; get_currentuserinfo(); if($userdata->user_level>9){?> <a class="hiddenLink" href="<?php echo home_url( '/' ); ?>?page_id=290">איך להכניס ולערוך תכנים באתר?</a> <?php } ?> </div> <div class="mobileHide"> <input type="radio" id="mobileClose" name="mobileButton"> <label class="menuBotton" for="mobileClose"></label> <input type="radio" id="mobileOpen" name="mobileButton"> <label class="menuBotton" for="mobileOpen"></label> <div class="mobileMenu"> <?php wp_nav_menu( array('menu' => 'main cat menu' ) ); ?> <?php wp_nav_menu( $menuARG ); ?> </div> </div> <div class="navLinksHolder"> <?php $menuARG = array( 'theme_location' => 'primary', 'menu_class' => 'nav-menu', 'before' => '<span class="beforeItem"></span>', ); ?> <?php wp_nav_menu( $menuARG ); ?> <a style="display:none;" class="myRecipesLink" href="">המתכונים שלי</a> <?php global $userdata; get_currentuserinfo(); if($userdata->user_level>9){ ?> <a class="menuEditLink" href="http://www.feincook.co.il/wp-admin/nav- menus.php?action=edit&menu=5" target="_blank">עריכת תפריט</a> <?php } ?> </div> <?php if ( is_home() ) { $catMenuLocal = homepage; } else { $catMenuLocal = regular; } if(is_category()){}; if(is_single()){ $cats = wp_get_post_categories($post->ID); $thecatid = $cats[0]; }; ?> <div class="currentCircle"></div> <div class="mainCatMenu cat<?php echo $thecatid; ?> " id="<?php echo $catMenuLocal ?>"> <?php wp_nav_menu( array('menu' => 'main cat menu' ) ); ?> </div> </div> </div> <!-- / .headerWrapper --> <div id="main" class="site-main swatch<?php meta('colorSwatch'); ?>">

cellFilter: 'date:"longDate"'