java 时间转中文_使用JScript把时间转成中文

测试页

function TimeCtrl()

{

this.DateObj = new Date();

this.toGb = function(Str)

{

Str = Str.toString();

if(/^\d+$/.test(Str))

{

var NewStr = "";

var GBNum = "零一二三四五六七八九";

for(var i = 0; i < Str.length; i++)

{

NewStr += GBNum.charAt(Str.charAt(i).valueOf());

}

return NewStr;

}

else

{

return "";

}

}

this.GetYear = function (Format)

{

var Year = this.DateObj.getFullYear().toString();

Format = Format.toString();

if(Format == "yy")

{

return Year.substr(2);

}

else if(Format == "YY")

{

return this.toGb(Year.substr(2));

}

else if(Format == "YYYY")

{

return this.toGb(Year);

}

else

{

return Year;

}

}

this.GetMonth = function (Format)

{

var Month = (parseInt(this.DateObj.getMonth()) + 1).toString();

Format = Format.toString();

if(Format == "mm")

{

if(Month.length == 1)

{

Month = "0" + Month;

}

return Month;

}

else if(Format == "M")

{

return this.toGb(Month);

}

else if(Format == "MM")

{

if(Month.length == 1)

{

Month = "0" + Month;

}

return this.toGb(Month);

}

else

{

return Month;

}

}

this.GetDate = function (Format)

{

var date = parseInt(this.DateObj.getDate()).toString();

Format = Format.toString();

if(Format == "dd")

{

if(date.length == 1)

{

date = "0" + date;

}

return date;

}

else if(Format == "D")

{

return this.toGb(date);

}

else if(Format == "DD")

{

if(date.length == 1)

{

date = "0" + date;

}

return this.toGb(date);

}

else

{

return date;

}

}

this.GetHour = function (Format)

{

var Hour = parseInt(this.DateObj.getHours()).toString();

Format = Format.toString();

if(Format == "hh")

{

if(Hour.length == 1)

{

Hour = "0" + Hour;

}

return Hour;

}

else if(Format == "H")

{

return this.toGb(Hour);

}

else if(Format == "HH")

{

if(Hour.length == 1)

{

Hour = "0" + Hour;

}

return this.toGb(Hour);

}

else

{

return Hour;

}

}

this.GetMinute = function (Format)

{

var Minute = parseInt(this.DateObj.getMinutes()).toString();

Format = Format.toString();

if(Format == "minm")

{

if(Minute.length == 1)

{

Minute = "0" + Minute;

}

return Minute;

}

else if(Format == "MIN")

{

return this.toGb(Minute);

}

else if(Format == "MINM")

{

if(Minute.length == 1)

{

Minute = "0" + Minute;

}

return this.toGb(Minute);

}

else

{

return Minute;

}

}

this.GetSecond = function (Format)

{

var Second = parseInt(this.DateObj.getSeconds()).toString();

Format = Format.toString();

if(Format == "ss")

{

if(Second.length == 1)

{

Second = "0" + Second;

}

return Second;

}

else if(Format == "S")

{

return this.toGb(Second);

}

else if(Format == "SS")

{

if(Second.length == 1)

{

Second = "0" + Second;

}

return this.toGb(Second);

}

else

{

return Second;

}

}

this.GetWeek = function(Format)

{

Format = Format.toString();

Week = parseInt(this.DateObj.getDay()).toString();

if(Format == "W")

{

return this.toGb(Week);

}

else if(Format == "WX")

{

if(Week == "0")

{

return "星期天";

}

else

{

return "星期" + this.toGb(Week);

}

}

else if(Format == "WL")

{

if(Week == "0")

{

return "礼拜天";

}

else

{

return "礼拜" + this.toGb(Week);

}

}

else if(Format == "WZ")

{

if(Week == "0")

{

return "周日";

}

else

{

return "周" + this.toGb(Week);

}

}

else

{

return Week;

}

}

this.IsLeap = function()

{

return (this.DateObj.getFullYear() % 4 == 0 && this.DateObj.getFullYear() % 100 != 0) || this.DateObj.getFullYear() % 400 == 0;

}

this.FormatDate = function(Format)

{

var FormatStr = Format.toString();

FormatStr = FormatStr.replace(/{yy}/g,this.GetYear("yy"));

FormatStr = FormatStr.replace(/{yyyy}/g,this.GetYear("yyyy"));

FormatStr = FormatStr.replace(/{YY}/g,this.GetYear("YY"));

FormatStr = FormatStr.replace(/{YYYY}/g,this.GetYear("YYYY"));

FormatStr = FormatStr.replace(/{m}/g,this.GetMonth("m"));

FormatStr = FormatStr.replace(/{mm}/g,this.GetMonth("mm"));

FormatStr = FormatStr.replace(/{M}/g,this.GetMonth("M"));

FormatStr = FormatStr.replace(/{MM}/g,this.GetMonth("MM"));

FormatStr = FormatStr.replace(/{d}/g,this.GetDate("d"));

FormatStr = FormatStr.replace(/{dd}/g,this.GetDate("dd"));

FormatStr = FormatStr.replace(/{DD}/g,this.GetDate("DD"));

FormatStr = FormatStr.replace(/{D}/g,this.GetDate("D"));

FormatStr = FormatStr.replace(/{w}/g,this.GetWeek("w"));

FormatStr = FormatStr.replace(/{W}/g,this.GetWeek("W"));

FormatStr = FormatStr.replace(/{WX}/g,this.GetWeek("WX"));

FormatStr = FormatStr.replace(/{WZ}/g,this.GetWeek("WZ"));

FormatStr = FormatStr.replace(/{WL}/g,this.GetWeek("WL"));

FormatStr = FormatStr.replace(/{h}/g,this.GetHour("h"));

FormatStr = FormatStr.replace(/{hh}/g,this.GetHour("hh"));

FormatStr = FormatStr.replace(/{H}/g,this.GetHour("H"));

FormatStr = FormatStr.replace(/{HH}/g,this.GetHour("HH"));

FormatStr = FormatStr.replace(/{min}/g,this.GetMinute("min"));

FormatStr = FormatStr.replace(/{minm}/g,this.GetMinute("minm"));

FormatStr = FormatStr.replace(/{MIN}/g,this.GetMinute("MIN"));

FormatStr = FormatStr.replace(/{MINM}/g,this.GetMinute("MINM"));

FormatStr = FormatStr.replace(/{s}/g,this.GetSecond("s"));

FormatStr = FormatStr.replace(/{ss}/g,this.GetSecond("ss"));

FormatStr = FormatStr.replace(/{S}/g,this.GetSecond("S"));

FormatStr = FormatStr.replace(/{SS}/g,this.GetSecond("SS"));

return FormatStr;

}

}

实例一(综合):

平常格式: 中文格式:

实例二(FormatDate):

平常格式:中文格式:

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/526036.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

java比赛用多重for_关于 Java 中 for的多重循环

1、i1&#xff0c;赋值2、判断 i < 3(i为1)&#xff0c;结果为 true&#xff0c;进入循环体 A&#xff1a;for (int j 1;j < i;j) {System.out.print("*");} System.out.println(); 这部分。3.0、执行循环体 A。3.1、j 1&#xff0c;赋值3.2、判断 j < i …

java 程序流程控制知识点_JAVA基础知识点梳理三:流程控制语句

条件语句之 if语法&#xff1a;执行过程&#xff1a;例&#xff1a;int score 65;if (score > 60) {System.out.println("该学生及格");}//注&#xff1a;如果 if 条件成立时的执行语句只有一条&#xff0c;大括弧可以省略&#xff0c;但如果执行语句有多条&…

寂静岭3java攻略_《寂静岭3HD》通关心得:感人之佳作

作者&#xff1a;jet1942(原帖点击进入)寂静岭是什么?它是人的内心世界,它是人赎罪的地方。读了这句话后&#xff0c;是不是感觉意境非常深邃&#xff0c;还带有些恐怖感?是的&#xff0c;这就是寂静岭的魅力所在&#xff0c;作为一款AVG类游戏&#xff0c;他与生化危机不同&…

java不要无限循环_java – 看似无限循环终止,除非使用System.out.println

我有一个简单的代码,应该是一个无限循环,因为x将永远增长,并将始终保持大于j.int x 5;int y 9;for (int j 0; j < x; j) {x x y;}System.out.println(y);但是按原样,它打印y并且不会无休止地循环.我无法弄清楚为什么.但是,当我按以下方式调整代码时&#xff1a;int x …

jpg无损压缩 java_使用FreeImage对JPEG进行无损优化

您可以使用FreeImage删除元数据&#xff0c;但是&#xff0c;对于jpeg&#xff0c;图像将在保存时重新压缩&#xff0c;并伴随相关的图像质量损失 . by default, FreeImage will have copied the metadata to the new imageIf Not (args.CopyMetadata) ThenDim tag As New Free…

mysql数据应用从入门_MYSQL数据库应用从入门到精通----读书笔记

mysql1、创建数据库create database database_name;2、查看数据库show database_name;3、选择数据库use database_name;4、删除数据库drop database database_name;5、认识支持的存储引擎show engines \g;6、创建数据库表create table t_dept(deptno int,dname varchar(20),loc…

Java zset 应用_Java简单使用redis-zset实现排行榜

简单使用redis-zset实现排行榜此方法实现一个根据某字段的查询次数进行排行&#xff0c;查询的次数越多排行越前(从大到小排序)&#xff0c;适用于初学者1.添加依赖org.springframework.bootspring-boot-starter-data-redis2.注入RedisTemplate方法Autowiredpublic RedisTempla…

安卓的java无法访问网络_Android网络访问的基本方法

Android访问网络的两种主要方式&#xff1a;1、标准Java接口(java.net) ----HttpURLConnection&#xff0c;可以实现简单的基于URL请求、响应功能&#xff1b;2、Apache接口(org.appache.http)----HttpClient&#xff0c;使用起来更方面更强大。一般来说&#xff0c;用这种接口…

create用法java_Java AcousticEchoCanceler.create方法代碼示例

import android.media.audiofx.AcousticEchoCanceler; //導入方法依賴的package包/類Overridepublic boolean initCapturer() {// initalize audio modeaudioManagerMode.acquireMode(audioManager);// get the minimum buffer size that can be usedint minRecBufSize AudioR…

form表单图片预览 layui_layui 实现图片上传和预览

[学习笔记]图片不自动上传并在表单提交时再上传&#xff0c;看代码。附上表单页面前台实现autocomplete"off" class"layui-input" disabled>autocomplete"off" class"layui-input">上传图片确定layui.use([form, layer, upload]…

java不会框架怎么办_感觉学java无从下手了,各种框架乱七八糟,感觉好乱。该怎么办!?...

image各种各样的编程语言不断崛起&#xff0c;但唯有Java是牢牢占据着老大的位置&#xff0c;目前几乎90%以上的大中型互联网应用系统在服务器端开发首选Java。因此&#xff0c;也是吸引了不少年轻人投入到Java的学习之中。但不得不说&#xff0c;Java作为老牌编程语言&#xf…

java基数排序 数组_万字长文带你掌握Java数组与排序,代码实现原理都帮你搞明白!...

查找元素索引位置基本查找根据数组元素找出该元素第一次在数组中出现的索引public class TestArray1 {public static void main(String[] args) {//定义一个数组int[] arr{10,20,70,10,90,100,1,2};//根据元素查找出该元素在数组中第一次出现的索引int indexgetIndexByEle(arr,…

php base64_decode 图片,php base64保存为图片,带格式解析

/*** 将base64字符串创建为图片文件* param string $base64 base64原始字符串* param string $path 保存文件的目录* param string $filename 文件名(不要带格式后缀)* return array 成功:state 1 filename:返回的文件名 失败:state 2 err:返回详细错误*/function createB…

php置顶文章,php实现文章置顶功能的方法

本文实例讲述了php实现文章置顶功能的方法。分享给大家供大家参考&#xff0c;具体如下&#xff1a;昨天客户让做文章置顶的功能。自己以前没做过。靠着同事的指点才做了出来。本来挺简单的事情&#xff0c;被自己搞了好久。自己真的缺乏对程序的理解。还是写篇博客记录一下吧。…

php 生成树,PHP超牛逼无限极分类生成树方法

你还在用浪费时间又浪费内存的递归遍历无限极分类吗&#xff0c;看了该篇文章&#xff0c;我觉得你应该换换了。这是我在OSChina上看到的一段非常精简的PHP无限极分类生成树方法&#xff0c;巧在引用&#xff0c;整理分享了。function generateTree($items){$tree array();for…

php curl put,PHP curl以模拟put请求,后台无法接受到数据是怎么回事?

我自己封装了curl工具类,测试表现:get,post,delete方式后台都能正确接收到前面传的参数,但是put方式就是获取不到参数.1.相关代码:index.php 入口请求文件require_once MyCurl.class.php;$data [param > 成功, param1 > 这是神马];$res MyCurl::send(http://localhost/…

php是走什么协议,TCP是什么协议

TCP代表传输控制协议&#xff0c;是Internet协议套件中的基本协议&#xff0c;是一种网络通信协议&#xff1b;它规定如何建立和维护两个程序可以交换数据的连接&#xff0c;通过Internet发送信息的方式。TCP代表传输控制协议&#xff0c;是Internet协议套件中的基本协议&#…

php 获取相反值,php – 以相反的顺序从单向数组中获取数据

你不是在寻找阵列的反面,但是你正在寻找相反的东西.首先要更好地理解这种逆转可能会对你有所帮助.您需要每个元素的父元素.如果您遍历下一个,则父级始终是前一个.因此,如果您将前一个元素添加为父元素,那么数组的最后一个元素就是您要查找的元素.所以听起来很直接.更难的部分是…

php网页调用ckeditor,php调用ckeditor?怎么调用ckeditor

怎么调用ckeditor呢&#xff0c;下面小编来给大家总结一处利用php 调用ckeditor编辑器与js调用ckeditor的方法吧&#xff0c;其它脚本调用方法大致一样了。PHP调用FCKeditor将FCKeditor放在网站根目录在PHP文件里面&#xff0c;包含/FCKeditor/ckeditor/" target"_bl…

php调用selenium,通过PHP exec()执行Selenium webdriver

我构建了一个python脚本&#xff0c;它使用Selenium和Firefox加载一些网站并处理它们的内容。因为我想在PHP中使用该脚本的输出&#xff0c;所以我使用PHP的exec()函数。在我的python测试脚本如下所示&#xff1a;from pyvirtualdisplay import Displayfrom selenium import we…