ASP以日期为名创建日志文件,并写入日志内容

步骤:

1、 格式化日期,以日期为文件名

2、判断文件是否存在,不存在就创建

3、将日志内容写入txt文本

<%
'/**
' * 写入日志到txt文本
' * sWord 日志内容
' *
Function LogResult(sWord)
	txtpath = Server.MapPath("log/"&FormatDate(Now(),2)&".txt")
    Set fso = Server.CreateObject("Scripting.FileSystemobject")
	' 判断文件是否存在,不存在就创建
    if  fso.FileExists(txtpath)=false then fso.CreateTextFile(txtpath) End if
    set cnrs = fso.OpenTextFile(txtpath,8)
        cnrs.WriteLine(FormatDate(Now(),1)&" "&sWord)
        cnrs.Close 
   set cnrs = nothing 
   set fso = nothing 
End Function

'/**
' * 日期格式化
' * DateAndTime 时间戳
' * datetype    显示的日期类型,1为2021-01-13 12:01:15
' *
Function FormatDate(DateAndTime, datetype)
	On Error Resume Next
    Dim y, m, d, h, mi, s, strDateTime
	If Not IsNumeric(datetype) Then Exit Function
	If Not IsDate(DateAndTime) Then Exit Function 
    y = CStr(Year(DateAndTime)) 
    m = CStr(Month(DateAndTime)) 
    If Len(m) = 1 Then m = "0" & m 
    d = CStr(Day(DateAndTime)) 
    If Len(d) = 1 Then d = "0" & d 
    h = CStr(Hour(DateAndTime)) 
    If Len(h) = 1 Then h = "0" & h 
    mi = CStr(Minute(DateAndTime)) 
    If Len(mi) = 1 Then mi = "0" & mi 
    s = CStr(Second(DateAndTime)) 
    If Len(s) = 1 Then s = "0" & s 
    Select Case datetype 
    Case "1" 
        strDateTime = y & "-" & m & "-" & d & " " & h & ":" & mi & ":" & s 
    Case "2" 
        strDateTime = y & "-" & m & "-" & d 
    Case "3" 
        strDateTime = y & "/" & m & "/" & d 
    Case "4" 
        strDateTime = y & "年" & m & "月" & d & "日" 
    Case "5" 
        strDateTime = m & "-" & d & " " & h & ":" & mi 
    Case "6" 
        strDateTime = m & "/" & d 
    Case "7" 
        strDateTime = m & "月" & d & "日" 
    Case "8" 
        strDateTime = y & "年" & m & "月" 
    Case "9" 
        strDateTime = y & "-" & m 
    Case "10" 
        strDateTime = y & "/" & m 
    Case "11" 
        strDateTime = right(y,2) & "-" &m & "-" & d & " " & h & ":" & mi 
    Case "12" 
        strDateTime = right(y,2) & "-" &m & "-" & d 
    Case "13" 
        strDateTime = m & "-" & d 
    Case Else 
        strDateTime = DateAndTime 
    End Select 
    FormatDate = strDateTime
End Function
%>

调用示例:

<%
LogResult("元宝支付 http://18pay.net/")
%>

效果如下图:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值