js中将日期类型转换成字符串型格式
2005-03-13 20:44
1026 查看
<script language="javascript">
/////////////////////////////////e///////////////////////
// 取得当前日期,格式yyyy-mm-dd
////////////////////////////////////////////////////////
function GetCurrentDate()
{
var Year=0;
var Month=0;
var Day=0;
var CurrentDate = new Date();
return ChangeDateToString(CurrentDate);
}
/////////////////////////////////e///////////////////////
// 取得当前日期,格式yyyy-mm-dd hh:mm
////////////////////////////////////////////////////////
function GetCurrentTime()
{
var Year=0;
var Month=0;
var Day=0;
var CurrentDate = new Date();
return ChangeTimeToString(CurrentDate);
}
////////////////////////////////////////////////////////
// 将日期类型转换成字符串型格式yyyy-MM-dd
////////////////////////////////////////////////////////
function ChangeDateToString(DateIn)
{
var Year=0;
var Month=0;
var Day=0;
var CurrentDate="";
//初始化时间
Year = DateIn.getYear();
Month = DateIn.getMonth()+1;
Day = DateIn.getDate();
CurrentDate = Year + "-";
if (Month >= 10 )
{
CurrentDate = CurrentDate + Month + "-";
}
else
{
CurrentDate = CurrentDate + "0" + Month + "-";
}
if (Day >= 10 )
{
CurrentDate = CurrentDate + Day ;
}
else
{
CurrentDate = CurrentDate + "0" + Day ;
}
return CurrentDate;
}
///////////////////////////////////////////////////////
// 将日期类型转换成字符串型格式yyyy-MM-dd hh:mm
////////////////////////////////////////////////////////
function ChangeTimeToString(DateIn)
{
var Year=0;
var Month=0;
var Day=0;
var Hour = 0;
var Minute = 0;
var CurrentDate="";
//初始化时间
Year = DateIn.getYear();
Month = DateIn.getMonth()+1;
Day = DateIn.getDate();
Hour = DateIn.getHours();
Minute = DateIn.getMinutes();
CurrentDate = Year + "-";
if (Month >= 10 )
{
CurrentDate = CurrentDate + Month + "-";
}
else
{
CurrentDate = CurrentDate + "0" + Month + "-";
}
if (Day >= 10 )
{
CurrentDate = CurrentDate + Day ;
}
else
{
CurrentDate = CurrentDate + "0" + Day ;
}
if(Hour >=10)
{
CurrentDate = CurrentDate + " " + Hour ;
}
else
{
CurrentDate = CurrentDate + " 0" + Hour ;
}
if(Minute >=10)
{
CurrentDate = CurrentDate + ":" + Minute ;
}
else
{
CurrentDate = CurrentDate + ":0" + Minute ;
}
return CurrentDate;
}
</script>
/////////////////////////////////e///////////////////////
// 取得当前日期,格式yyyy-mm-dd
////////////////////////////////////////////////////////
function GetCurrentDate()
{
var Year=0;
var Month=0;
var Day=0;
var CurrentDate = new Date();
return ChangeDateToString(CurrentDate);
}
/////////////////////////////////e///////////////////////
// 取得当前日期,格式yyyy-mm-dd hh:mm
////////////////////////////////////////////////////////
function GetCurrentTime()
{
var Year=0;
var Month=0;
var Day=0;
var CurrentDate = new Date();
return ChangeTimeToString(CurrentDate);
}
////////////////////////////////////////////////////////
// 将日期类型转换成字符串型格式yyyy-MM-dd
////////////////////////////////////////////////////////
function ChangeDateToString(DateIn)
{
var Year=0;
var Month=0;
var Day=0;
var CurrentDate="";
//初始化时间
Year = DateIn.getYear();
Month = DateIn.getMonth()+1;
Day = DateIn.getDate();
CurrentDate = Year + "-";
if (Month >= 10 )
{
CurrentDate = CurrentDate + Month + "-";
}
else
{
CurrentDate = CurrentDate + "0" + Month + "-";
}
if (Day >= 10 )
{
CurrentDate = CurrentDate + Day ;
}
else
{
CurrentDate = CurrentDate + "0" + Day ;
}
return CurrentDate;
}
///////////////////////////////////////////////////////
// 将日期类型转换成字符串型格式yyyy-MM-dd hh:mm
////////////////////////////////////////////////////////
function ChangeTimeToString(DateIn)
{
var Year=0;
var Month=0;
var Day=0;
var Hour = 0;
var Minute = 0;
var CurrentDate="";
//初始化时间
Year = DateIn.getYear();
Month = DateIn.getMonth()+1;
Day = DateIn.getDate();
Hour = DateIn.getHours();
Minute = DateIn.getMinutes();
CurrentDate = Year + "-";
if (Month >= 10 )
{
CurrentDate = CurrentDate + Month + "-";
}
else
{
CurrentDate = CurrentDate + "0" + Month + "-";
}
if (Day >= 10 )
{
CurrentDate = CurrentDate + Day ;
}
else
{
CurrentDate = CurrentDate + "0" + Day ;
}
if(Hour >=10)
{
CurrentDate = CurrentDate + " " + Hour ;
}
else
{
CurrentDate = CurrentDate + " 0" + Hour ;
}
if(Minute >=10)
{
CurrentDate = CurrentDate + ":" + Minute ;
}
else
{
CurrentDate = CurrentDate + ":0" + Minute ;
}
return CurrentDate;
}
</script>
相关文章推荐
- js 日期格式转换---将日期类型转换成字符串型格式
- 用js 将long类型转换成日期格式
- Js中将Long转换成日期格式的实现方法
- JS中将毫秒转换成任意日期格式
- springMVC类型转换,提交日期字符数据自动转换日期格式
- android开发过程中将json日期字符串,转换成JAVA中Date类型格式化字符串
- 在js中将number类型的数据转换成保留两位小数的字符串
- discuz x2.5中将文章列表或内容页的长日期格式转换成短日期格式(Y-m-d H:i:s)-> (Y-m-d)
- JS 将字符串转换成日期类型
- SAS 日期格式转换成字符或数字
- js 将php生成的time()类型时间戳转化成具体date格式的日期
- 字符串转换成js的日期格式
- js转换Date日期格式
- JS、Jquery实现---把后台传过来的时间毫秒数转换成想要的日期格式
- js 日期字符串转换成日期类型,判断星期几
- 日期格式(Date)与Long类型之间的互相转换
- JS 将字符串转换成日期类型 (20
- JS日期格式的转换
- JS 将字符串转换成日期类型
- js将日期格式的时候转换成时间搓