zoukankan      html  css  js  c++  java
  • js日期格式“补零”

    js 代码:

    var day=0;
    var month=0;
    var year=0;
    var today="";
    mydate=new Date();
    mymonth=mydate.getMonth()+1;
    myday= mydate.getDate();
    myyear= mydate.getFullYear();
    year=(myyear > 200) ? myyear : 1900 + myyear;
    if(mymonth >= 10){mymonth=mymonth;}else{mymonth="0" + mymonth;}
    if(myday >= 10){myday=myday;}else{myday="0" + myday;}
    today=year+'-'+mymonth+'-'+myday;

    调用:$("#applydate").val(today);

    呵呵,同时要加载jquery插件

    /////////////////////////////////////////////////////////////

    asp版

    Function FormatTime(s_Time, n_Flag)
     Dim y, m, d, h, mi, s
     FormatTime = ""
     If IsDate(s_Time) = False Then Exit Function
     y = cstr(year(s_Time))
     m = cstr(month(s_Time))
     If len(m) = 1 Then m = "0" & m
     d = cstr(day(s_Time))
     If len(d) = 1 Then d = "0" & d
     h = cstr(hour(s_Time))
     If len(h) = 1 Then h = "0" & h
     mi = cstr(minute(s_Time))
     If len(mi) = 1 Then mi = "0" & mi
     s = cstr(second(s_Time))
     If len(s) = 1 Then s = "0" & s
     Select Case n_Flag
     Case 1
     ' yyyy-mm-dd hh:mm:ss
     FormatTime = y & "-" & m & "-" & d & " " & h & ":" & mi & ":" & s
     Case 2
     ' yyyy-mm-dd
     FormatTime = y & "-" & m & "-" & d
     Case 3
     ' hh:mm:ss
     FormatTime = h & ":" & mi & ":" & s
     Case 4
     ' yyyy年mm月dd日
     FormatTime = y & "年" & m & "月" & d & "日"
     Case 5
     ' yyyymmdd
     FormatTime = y & m & d
     case 6
     'yyyymmddhhmmss
     FormatTime= y & m & d & h & mi & s
     End Select
    'response.Write(FormatTime)
    End Function

  • 相关阅读:
    python中的各种排序
    python 实现求和、计数、最大最小值、平均值、中位数、标准偏差、百分比。
    python中的lambda
    python中有趣的函数
    python中的小技巧
    python 删除list中重复元素
    django-pagination的使用
    django-south
    ios复制到剪贴板
    iOS系统验证关闭
  • 原文地址:https://www.cnblogs.com/shoupifeng/p/2239446.html
Copyright © 2011-2022 走看看