In Chapter I, we have a rough indication of the year, when Inspector MacDonald arrives (p. 4):
Those were the early days at the end of the ’80’s, when Alec MacDonald was far from having attained the national fame which he has now achieved.
For comparison, this falls around the time of one of Doyle's earliest works, The Sign of the Four, set in 1888. Now, at the end of the first part, Watson asks readers to "journey back some twenty years in time" for the second part of the story, which takes place in 1874 and 1875. Clearly, the first part can't take place in 1895 because Moriarty was dead by then - The Final Problem takes place in 1891. So if we assume that "twenty years" is an approximation, we can place The Valley of Fear at 1888 or 1889.
I would place the story at 1889, given that it's a better approximation, but Watson appears to be living with Holmes at the time. In the epilogue, they receive a letter:
Then one morning there came an enigmatic note slipped into our letter box.
This is further supported when it is confirmed that Mrs. Hudson is still the pair's landlady.
Dr. Watson married sometime in 1889, meaning that the events took place sometime that year or in 1888 - possibly 1888. It appears that Watson married in 1888, as per The Adventure of the Noble Bachelor.
We can be more specific as to the day. Holmes notes that he ordered the new edition of Whitaker’s Almanac because it is January 7th of the new year.
I have some evidence here and there that Holmes has known about Moriarty for perhaps a few years. It must not have been too long, because while when Holmes first mentions Moriarty (p. 1), Watson exclaims that he has heard about the criminal before (from Holmes) - although in The Final Problem, he states that he has never heard of him! Likewise, the police are likely unaware of Moriarty's doings. MacDonald tells Holmes that Scotland Yard and other agencies have a favorable impression of the Professor (p. 5):
. . . we think in the C. I. D. that you have a wee bit of a bee in your bonnet over this professor. I made some inquiries myself about the matter. He seems to be a very respectable, learned, and talented sort of man.”
Holmes changes this impression by pointing out that Moriarty could not afford several luxuries than he has - a painting by Jean Baptiste Greuze, for instance - on a professor's salary. This may be the first time the police consider Moriarty a potential criminal, which is admittedly unsurprising, given that Moriarty's web keeps him well-hidden.
Holmes does say that he has been in Moriarty's rooms three time on various occasions, though he has yet to meet the Professor himself. He also mentions that he has "dozens of exiguous threads" that implicate Moriarty in various crimes, and that it could take MacDonald anywhere from three months to two years to study him. This suggests that Holmes has been aware of Moriarty's activities for some time - possibly a few years.
Putting this all together, I think we can estimate that Holmes knew about Moriarty since at least, say, 1885 or 1886.