如何仅从角度Js中的MySQL数据库日期戳获取日期

时间:2015-06-18 14:18:48

标签: javascript json angularjs laravel

我需要使用此处给出的JSON中的created_at并使用angular,我只需要打印日期。怎么做?

files":{"65":[{"id":5,"ticket_id":65,"file_name":"1434545168_South Park s10e10 - Miss Teacher Bangs a Boy _ 480p UNCENSORED x264 NIT158.srt","file_size":"30893","file_url":"http:\/\/localhost\/levigo\/storage\/app\/1434545168_South Park s10e10 - Miss Teacher Bangs a Boy _ 480p UNCENSORED x264 NIT158.srt","**created_at":"2015-06-17 18:16:08"**},{"id":6,"ticket_id":65,"file_name":"1434545196_6croMg5xi.png","file_size":"65412","file_url":"http:\/\/localhost\/levigo\/storage\/app\/1434545196_6croMg5xi.png","created_at":"2015-06-17 18:16:36"},{"id":7,"ticket_id":65,"file_name":"1434545214_6croMg5xi.png","file_size":"65412","file_url":"http:\/\/localhost\/levigo\/storage\/app\/1434545214_6croMg5xi.png","created_at":"2015-06-17 18:16:54"}],"66":[]}

我通过制作我的过滤器来完成此操作,但它无效并且输出错误

myApp.filter('format', function () {
      return function (item) {
           var t = item.split(/[- :]/);
       var d = new Date(t[0], t[1]-1, t[2], t[3], t[4], t[5]);
       var time=d.getTime();                 
               return time;
      };
    });

2 个答案:

答案 0 :(得分:1)

根据您的需要,您可以保持简单:

app.filter('format', function () {
      return function (item) {
        return new Date(item);
      };
    });

然后在你看来:

{{modelVariable | format | date}}

这将显示Jun 17, 2015

plunker

或者完全跳过过滤器:

$scope.theDate = new Date(2015-06-17 18:16:08);

{{theDate | date}}

答案 1 :(得分:0)

public class Splashscreen extends Activity {
String urls = "xxxxxxxxxxxxxxx";
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.splash_screen);
    if (android.os.Build.VERSION.SDK_INT > 9) {
        StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
                .permitAll().build();
        StrictMode.setThreadPolicy(policy);
    }


    try {
        new MyTask().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
    } catch (Exception e) {
        // TODO: handle exception
    }
}
class MyTask extends AsyncTask<Void, Void, Void>{
    @Override
    protected Void doInBackground(Void... params) {
        RSSFeed_SAXParser saxParser = new RSSFeed_SAXParser(urls);
        Log.i("ClearBef", "----------------Cache-Clear-----------");

        Log.v("getTitleList", "="+saxParser.getTitleList().size());
        Log.v("getImageUrllist", "="+saxParser.getImageUrllist().size());
        Log.v("getDurationList", "="+saxParser.getDurationList().size());
        Log.v("getVideoUrllist", "="+saxParser.getVideoUrllist().size());
        Log.v("getBitrateUrllist", "="+saxParser.getBitrateUrllist().size());
        Log.v("getGuidlist", "="+saxParser.getGuidlist().size());
        Log.d("getPubDateList", "="+saxParser.getPubDateList().size());
        return null;
    }
    @Override
    protected void onPostExecute(Void result) {
        Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            public void run() {
                finish();
                Intent intent = new Intent(getBaseContext(), MainActivity.class);

                // overridePendingTransition(R.anim.slide_in_left,R.anim.slide_out_right);
                startActivity(intent);
            }
        }, 100);
        super.onPostExecute(result);
    }
  }
 }

JS FIDDLE LINK