Offer to come, dig friends take it! I am participating in the 2022 Spring Recruit series activities spring Recruit punch task, click to seeEvent details

@TOC

preface

Hello! Friend!!! ଘ(੭, ᵕ)੭ Nickname: Haihong Name: program monkey | C++ player | Student profile: Because of C language, I got acquainted with programming, and then transferred to the computer major, and had the honor to win some state awards, provincial awards… Has been confirmed. Learning experience: solid foundation + more notes + more code + more thinking + learn English well! Xiaobai stage article only as their own study notes for the establishment of knowledge system and review to know why!

An error prompt

expect end-tag input., near div

/pages/index/index.wxml expect end-tag 'input'., near `div` 8 | <input type="text" name="" required=""> 9 | <label>Username</label> > 10 | </div> | ^ 11 | <div class="user-box"> 12 | <input type="password" name="" required=""/> 13 | <label>Password</label>Copy the code

An error code

    <div class="user-box">
            <input type="text" name="" required="">
            <label>Username</label>
          </div>
Copy the code

The solution

The problem is with the input tag

You need closure in small programs

Just add a /

Revised:

<input type="text" name="" required=""/>
Copy the code

Encapsulate the function to get the timestamp

Packaging function Create a custom folder for utils.jsutils.js

function formatTime(date) {
  var year = date.getFullYear()
  var month = date.getMonth() + 1
  var day = date.getDate()

  var hour = date.getHours()
  var minute = date.getMinutes()
  var second = date.getSeconds()

  return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')}function formatNumber(n) {
  n = n.toString()
  return n[1] ? n : '0' + n
}

module.exports = {
  formatTime: formatTime
}
Copy the code

Use the function ceshi.js

Var util = require(var util = require();'.. /utils/utils.js');
Page({
  data: {

  },
  onLoad: functionVar time = util.formatTime(new Date()); var time = util.formatTime(new Date()); Console. log(time)// Print test time}})Copy the code

The results of

2019/11/09 13:09:56
Copy the code

2. Get the timestamp yourself without wrapping the function

For example, I need the current year, month, and day. So we own at any time in JS access, ok. ceshi.js

Page({
  data: {

  },
  onLoad: function () {
let year=new Date().getFullYear()
letMonth =new Date().getMonth()+1let day=new Date().getDate()
let hour=new Date().getHours()
let minute=new Date().getMinutes()
let secend=new Date().getSeconds()
console.log("year="+year);
console.log("month="+month)
console.log("day="+day)
console.log("hour="+hour)
  }
})
Copy the code

The results of Note: Use getFullYear() to get informationparentheses!!!!

The picker component is used to obtain the time selected by the user and normalize it

1. Use the Picker component to get the user selection time

wxml

<view class="top_content">
		<picker mode="date" value="{{date}}" start="2015-09-01" end="2020-09-01" bindchange="DateChange">
<view class="top_contenta"</view> <text><text class="top_contentb">{{total_days}}</text>天</text>
		</picker>
</view>

Copy the code

js

 DateChange:function(e){// Select the time in e.daile.value console.log("The time selected by the user is:" + e.detail.value)    
}      
Copy the code

Results (console debug results)

The time selected by the user is 2019-11-09Copy the code

2, normalization, easy to find the date plus or minus JS

 DateChange:function(e){
    
    console.log("The time selected by the user is:"+ e.daile.value) // time normalize 2019-1-1== "2019/1/1 var start_date = e.daile.value. Replace (/-/g,"/"Parse (new Date(start_date)) var x = date.parse (new Date(start_date)); var y=Date.parse(new Date("2017-1-1"))// Custom string string== "Date // Verification result console.log("The number of milliseconds from 1970-1-1 selected by the user ="+x)
    console.log("2017-1-1 milliseconds from 1970-1-1 ="+y)
    console.log("The number of days between the two ="+(x-y)/(1000*3600*24))
}   
Copy the code

The results of

conclusion

The essay is just a study note, recording a process from 0 to 1

Hope to have a little help to you, if there is a mistake welcome small partners correct