asp 如何取Long时间,类似java System.currentTimeMillis()

asp 如何取Long时间,类似java System.currentTimeMillis(),第1张

vb和java的时间表示方案不同。

java中的时间用long型整数表示,是从1970-1-1 0:0:0开始的毫秒数;

vb中的时间用double型浮点数表示,整数部分是天数(从什么时候开始不清楚,好像不是1970-1-1了?),小数部分是一天内毫秒数的换算。

所以可以这个样子计算:

millsecs=cdbl(thetime)864001000 ' 86400是一天的秒数,1000是毫秒数

import javautil;

import javatext;

import javautilCalendar;

public class VeDate {

/

获取现在时间

@return 返回时间类型 yyyy-MM-dd HH:mm:ss

/

public static Date getNowDate() {

Date currentTime = new Date();

SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

String dateString = formatterformat(currentTime);

ParsePosition pos = new ParsePosition(8);

Date currentTime_2 = formatterparse(dateString, pos);

return currentTime_2;

}

/

获取现在时间

@return返回短时间格式 yyyy-MM-dd

/

public static Date getNowDateShort() {

Date currentTime = new Date();

SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");

String dateString = formatterformat(currentTime);

ParsePosition pos = new ParsePosition(8);

Date currentTime_2 = formatterparse(dateString, pos);

return currentTime_2;

}

/

获取现在时间

@return返回字符串格式 yyyy-MM-dd HH:mm:ss

/

public static String getStringDate() {

Date currentTime = new Date();

SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

String dateString = formatterformat(currentTime);

return dateString;

}

/

获取现在时间

@return 返回短时间字符串格式yyyy-MM-dd

/

public static String getStringDateShort() {

Date currentTime = new Date();

SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");

String dateString = formatterformat(currentTime);

return dateString;

}

/

获取时间 小时:分;秒 HH:mm:ss

@return

/

public static String getTimeShort() {

SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");

Date currentTime = new Date();

String dateString = formatterformat(currentTime);

return dateString;

}

/

将长时间格式字符串转换为时间 yyyy-MM-dd HH:mm:ss

@param strDate

@return

/

public static Date strToDateLong(String strDate) {

SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

ParsePosition pos = new ParsePosition(0);

Date strtodate = formatterparse(strDate, pos);

return strtodate;

}

/

将长时间格式时间转换为字符串 yyyy-MM-dd HH:mm:ss

@param dateDate

@return

/

public static String dateToStrLong(javautilDate dateDate) {

SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

String dateString = formatterformat(dateDate);

return dateString;

}

/

将短时间格式时间转换为字符串 yyyy-MM-dd

@param dateDate

@param k

@return

/

public static String dateToStr(javautilDate dateDate) {

SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");

String dateString = formatterformat(dateDate);

return dateString;

}

/

将短时间格式字符串转换为时间 yyyy-MM-dd

@param strDate

@return

/

public static Date strToDate(String strDate) {

SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");

ParsePosition pos = new ParsePosition(0);

Date strtodate = formatterparse(strDate, pos);

return strtodate;

}

/

得到现在时间

@return

/

public static Date getNow() {

Date currentTime = new Date();

return currentTime;

}

/

提取一个月中的最后一天

@param day

@return

/

public static Date getLastDate(long day) {

Date date = new Date();

long date_3_hm = dategetTime() - 3600000 34 day;

Date date_3_hm_date = new Date(date_3_hm);

return date_3_hm_date;

}

/

得到现在时间

@return 字符串 yyyyMMdd HHmmss

/

public static String getStringToday() {

Date currentTime = new Date();

SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd HHmmss");

String dateString = formatterformat(currentTime);

return dateString;

}

/

得到现在小时

/

public static String getHour() {

Date currentTime = new Date();

SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

String dateString = formatterformat(currentTime);

String hour;

hour = dateStringsubstring(11, 13);

return hour;

}

/

得到现在分钟

@return

/

public static String getTime() {

Date currentTime = new Date();

SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

String dateString = formatterformat(currentTime);

String min;

min = dateStringsubstring(14, 16);

return min;

}

/

根据用户传入的时间表示格式,返回当前时间的格式 如果是yyyyMMdd,注意字母y不能大写。

@param sformat

yyyyMMddhhmmss

@return

/

public static String getUserDate(String sformat) {

Date currentTime = new Date();

SimpleDateFormat formatter = new SimpleDateFormat(sformat);

String dateString = formatterformat(currentTime);

return dateString;

}

/

二个小时时间间的差值,必须保证二个时间都是"HH:MM"的格式,返回字符型的分钟

/

public static String getTwoHour(String st1, String st2) {

String[] kk = null;

String[] jj = null;

kk = st1split(":");

jj = st2split(":");

if (IntegerparseInt(kk[0]) < IntegerparseInt(jj[0]))

return "0";

else {

double y = DoubleparseDouble(kk[0]) + DoubleparseDouble(kk[1]) / 60;

double u = DoubleparseDouble(jj[0]) + DoubleparseDouble(jj[1]) / 60;

if ((y - u) > 0)

return y - u + "";

else

return "0";

}

}

/

得到二个日期间的间隔天数

/

public static String getTwoDay(String sj1, String sj2) {

SimpleDateFormat myFormatter = new SimpleDateFormat("yyyy-MM-dd");

long day = 0;

try {

javautilDate date = myFormatterparse(sj1);

javautilDate mydate = myFormatterparse(sj2);

day = (dategetTime() - mydategetTime()) / (24 60 60 1000);

} catch (Exception e) {

return "";

}

return day + "";

}

/

时间前推或后推分钟,其中JJ表示分钟

/

public static String getPreTime(String sj1, String jj) {

SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

String mydate1 = "";

try {

Date date1 = formatparse(sj1);

long Time = (date1getTime() / 1000) + IntegerparseInt(jj) 60;

date1setTime(Time 1000);

mydate1 = formatformat(date1);

} catch (Exception e) {

}

return mydate1;

}

并不是java的时间可以用毫秒来度量,而是计算机提供了毫秒精度的时间而已。

当你的代码调用java获取时间时,java会调用计算机系统获取系统时间。此时计算机会返回一个大数,这个数字是 “自 1970 年 1 月 1 日 00:00:00 GMT 以来的毫秒数”。通过转化,也就可以获取真实时间了。 不过精度也只能到毫秒,再高是无法实现的。因为计算机不给啊。

//获取当前时间前或后某分钟的时间毫秒数

public static long getTimeByMinute(int minute) {

        Calendar calendar = CalendargetInstance();

        calendaradd(CalendarMINUTE, minute);

        return calendargetTime()getTime();

 }

 //将毫秒数转换为时间字符串

 public static String formatDate(long millis){

  Calendar calendar = CalendargetInstance();

  if(millis<=0){

   millis = calendargetTimeInMillis();

  }

  calendarsetTimeInMillis(millis);

  SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

  return formatformat(calendargetTime());

 }

 当然你也可以把当前时间改为你传入的时间,如果算前多少分钟的话就传负值,如果算小时的话就把CalendarMINUTE改一下就可以了

 望采纳

以上就是关于asp 如何取Long时间,类似java System.currentTimeMillis()全部的内容,包括:asp 如何取Long时间,类似java System.currentTimeMillis()、java编程之怎样把Long转换成Date的日期格式、为什么java中的时间可以用毫秒来度量等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/9318989.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-27
下一篇2023-04-27

发表评论

登录后才能评论

评论列表(0条)

    保存