使用AngularJS / jQuery将24小时时间变量转换为12小时时间 [英] Convert 24 hours time variable into 12Hours time with AngularJS/jQuery

查看:133
本文介绍了使用AngularJS / jQuery将24小时时间变量转换为12小时时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从数据库中获取一个24小时时间字符串的值。
我正在寻找一种方法,使用angularJS或jQuery将此字符串更改为12小时时间。

I'm getting a value from database which is in 24 hours time string. I'm looking for a way to change this string in to 12 hours clock time using angularJS or jQuery.

我无法对代码进行任何更改目前是后端(JAVA)或数据库。

I can not do any code changes to the back-end(JAVA) or database at the moment.

var offTime = "17:25:11";

我需要它显示为:5:25:11

请帮忙!

推荐答案

你需要将值拆分,在通过模运算符运行第一个值后重建它。试试这个:

You need to split the value by :, the rebuild it after running the first value through the modulo operator. Try this:

var offTime = "17:25:11".split(':');
offTime[0] = offTime[0] % 12;
var output = offTime.join(':');

alert(output);

这篇关于使用AngularJS / jQuery将24小时时间变量转换为12小时时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆