2021-06-10

随机点名器:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
      *{
          margin:0;
          padding:0;
      }

      #main{
          margin:100px;
          background:rgba(245, 197, 224, 0.5);
          width:520px;
          padding:50px;
          box-shadow:0 2px 12px #666666;
      }

      #box{
          margin:50px;
          padding:20px;
          width: 250px;
          font-size:50px;
         
      }

      #btn{
          color:red;
          width:110px;
          font-size:20px;
          border-color: gainsboro;
          font-weight:bold;
          background-color:rgba(225, 247, 225, 0.4);
          border-radius:8px 8px 8px 8px;
          box-shadow:0 2px 12px #797878;
          cursor:pointer;
          padding:5px;
      }
    </style>
</head>
<body>
         <center>
          <div id="main">
              <div id="box">点击开始</div>
              <button id="btn" onclick="doit()">start<button>
                </div>
            </center>
            
            <script>
                //准备数据 用数组保存学生姓名
                var namelist=["Linda","Kate","Alice","Mike","Vivian","Abby","John","Tim","Jick","Chirs","Lily"];
                var btNode = document.getElementById('btn');
                var boxNode = document.getElementById('box');
                var timer;
                var flag =1;
                  //点击开始按钮
                function doit(){
                  if(flag){
                    start();
                    btNode.innerText="stop";
                    flag = 0;
                  }else{
                    stop();
                    btNode.innerText="start";
                    flag = 1;
                  }
                }
                //点击开始后开始做的事 设置定时任务随机抽取学生
                function start(){
                  timer = setInterval(function(){
                    var num = random(0,namelist.length);
                    //显示到页面
                    boxNode.innerText = namelist[num];
                  },100)
                }
                //点击暂停 清除定时器
                function stop (){
                   clearInterval(timer);
                }
                // 产生随机数 用于数据数组的下标使用
                function random(a,b){
                   return parseInt(Math.random() * (b - a) + a);
                }
            
            </script>
</body>
</html>

数组去重:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
        <script>
                var sz=new Array(2,34,2,5,6,9,8,4,34,67,6)
                var newarry=[]
                for(i=0;i<sz.length;i++){
                    for(j=i+1;j<=sz.length;j++){
                        if(sz[i]==sz[j]){
                            i++
                            j=i
                        }
                    }
                    newarry.push(sz[i])
                }
                console.log(newarry)
            </script>
</body>
</html>
在Java中,我们可以使用SimpleDateFormat类来将时间字符串转换为年月日格式。首先,你需要创建一个SimpleDateFormat的对象,并指定日期格式,例如"yyyy-MM-dd"表示年月日的格式。然后,使用该对象的parse()方法将时间字符串解析为一个Date对象。最后,再次使用SimpleDateFormat对象的format()方法将Date对象格式化为另一种日期格式,例如"yyyy年MM月dd日"表示年月日的格式。 以下是一个示例代码: ```java import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class DateConversion { public static void main(String[] args) { String dateString = "2021-06-10"; SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); try { Date date = dateFormat.parse(dateString); SimpleDateFormat outputFormat = new SimpleDateFormat("yyyy年MM月dd日"); String formattedDate = outputFormat.format(date); System.out.println(formattedDate); } catch (ParseException e) { e.printStackTrace(); } } } ``` 在上面的代码中,我们首先创建了一个SimpleDateFormat对象dateFormat,用于解析时间字符串"2021-06-10"。然后使用parse()方法将时间字符串解析为一个Date对象date。接下来,我们再次创建了一个SimpleDateFormat对象outputFormat,用于定义输出的日期格式为"yyyy年MM月dd日"。最后,使用format()方法将Date对象date格式化为所需的日期格式,并将结果打印出来。 运行以上代码,将输出"20210610日"。这样,我们就成功地将时间字符串转换为年月日格式。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值