您的位置:首页 > Web前端 > JavaScript

javascript6-系统对象

2016-07-17 15:11 267 查看
<!DOCTYPE html>
<html>
<head>
<metacharset="UTF-8">
<title></title>
</head>
<body>

<scripttype="text/javascript">
// Date 对象
// 记录时间的,时间对象
varnow
= new Date();
// alert(now);
// 年份获取
varyear
= now.getFullYear();
// alert(year);
// 月份获取 0 ~ 11
varmonth
= now.getMonth();
// alert(month);
// 日获取
varday
= now.getDate();
// alert(day);
// 星期
varweekday
= now.getDay();
// alert(weekday);
// 小时 24小时
varhour
= now.getHours();
// alert(hour);
// 分钟
varminute
= now.getMinutes();
// alert(minute);
// 秒
varsecond
= now.getSeconds();
// alert(second);
// 毫秒
varmillsecond
= now.getMilliseconds();
// alert(millsecond);

// 从1970年1月1日到现在的毫秒数
// 时间戳
vartime
= now.getTime();
// alert(time);

// 获取到指定时间
var future
= new Date(1949,
9, 1, 8,
30, 00);
alert(future);

// string 对象
// 万事万物皆对象
// 创建一个字符串
// var myStr = new String("hello js");
// alert(myStr.length);
// var str = "村雨于文文是天生一对";
// alert(str.length);
// 字符串对象方法:
// charAt(); 
// 查询某个下标处的字符;
// 必需。表示字符串中某个位置的数字,即字符在字符串中的下标。
// alert(str.charAt(0));

// search();
// 查找,返回值是查找到的位置。
// regexp;正则表达式
// 查找找到第一个出现的字符就返回下标位置, 如果没有找到任何匹配的字符串,则返回-1
// alert(str.search("文文"));

// 字符串拼接
// var str1 = "竖着";
// var str2 = "于";
// var str3 = "文文";
// 字符串是一种特殊形式的数组
// var newStr = str1.concat(str2, str3, "是天生一对");
// var newStr = str1 + str2 + str3;
// alert(newStr);

//indexOf(); 检索
// 竖着于文文是天生一对
// 查找首个出现的字符,返回其下标位置,如果找不到,返回-1
// indexOf(); 也可以应用于数组
// alert(str.indexOf("是"));
// var aa = [1, 5, 2, 4, 6];
// alert(aa.indexOf(4));

// lastIndexOf();
// 检索,从后往前检索,首次出现的字符,返回其下标位置
// str = "问问送货上门啊问问";
// alert(str.lastIndexOf("问问"));

// 字符串分割
// str = "i love u all night";
// split();
// 根据某一字符串来分割字符串,分割之后放到数组中
// var a = str.split(" ");
// alert(a[1]);

// 字符串连接
// join(); 数组的方法
// str = a.join("
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Date javascript string